Accessing AWS s3 files only from React Native App
I'm creating a react native app, which is using images and audiofiles from an AWS S3 bucket.
I use rails and carrierwave in the backend to upload images and audiofiles from the users.
But, I need the files to be only accessible by the users of the mobile app in some way.
I figured I would use a signed url, but this link can only last 7 days maximum, which is not working for this app. The files should be available until a deadline which could be anytime in the future.
Is there some way in AWS to say that these files can be viewed by everyone (or just the app) but not be downloaded? The reason I wan't this, is that the users should be able to decide if the audiofile is downloadable or not.
After finding out the signed url's are not valid longer than 7 days, I don't know how to accomplish this (pretty newbie with AWS)
ruby-on-rails amazon-web-services amazon-s3 carrierwave
add a comment |
I'm creating a react native app, which is using images and audiofiles from an AWS S3 bucket.
I use rails and carrierwave in the backend to upload images and audiofiles from the users.
But, I need the files to be only accessible by the users of the mobile app in some way.
I figured I would use a signed url, but this link can only last 7 days maximum, which is not working for this app. The files should be available until a deadline which could be anytime in the future.
Is there some way in AWS to say that these files can be viewed by everyone (or just the app) but not be downloaded? The reason I wan't this, is that the users should be able to decide if the audiofile is downloadable or not.
After finding out the signed url's are not valid longer than 7 days, I don't know how to accomplish this (pretty newbie with AWS)
ruby-on-rails amazon-web-services amazon-s3 carrierwave
add a comment |
I'm creating a react native app, which is using images and audiofiles from an AWS S3 bucket.
I use rails and carrierwave in the backend to upload images and audiofiles from the users.
But, I need the files to be only accessible by the users of the mobile app in some way.
I figured I would use a signed url, but this link can only last 7 days maximum, which is not working for this app. The files should be available until a deadline which could be anytime in the future.
Is there some way in AWS to say that these files can be viewed by everyone (or just the app) but not be downloaded? The reason I wan't this, is that the users should be able to decide if the audiofile is downloadable or not.
After finding out the signed url's are not valid longer than 7 days, I don't know how to accomplish this (pretty newbie with AWS)
ruby-on-rails amazon-web-services amazon-s3 carrierwave
I'm creating a react native app, which is using images and audiofiles from an AWS S3 bucket.
I use rails and carrierwave in the backend to upload images and audiofiles from the users.
But, I need the files to be only accessible by the users of the mobile app in some way.
I figured I would use a signed url, but this link can only last 7 days maximum, which is not working for this app. The files should be available until a deadline which could be anytime in the future.
Is there some way in AWS to say that these files can be viewed by everyone (or just the app) but not be downloaded? The reason I wan't this, is that the users should be able to decide if the audiofile is downloadable or not.
After finding out the signed url's are not valid longer than 7 days, I don't know how to accomplish this (pretty newbie with AWS)
ruby-on-rails amazon-web-services amazon-s3 carrierwave
ruby-on-rails amazon-web-services amazon-s3 carrierwave
asked Nov 24 '18 at 22:29
Marius WMarius W
106
106
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The code is pretty crude as I spend most of my time in Node + Go, but I think it gets the primary point across.
You want to create an endpoint in your API to control playing files. All interaction with the file will be done through this endpoint that way you can control access to the file in any way that you want.
class SoundFileController < ActionController::Base
def getFile
file = SoundFile.get(params[:fileId])
//do some validation to determine if you can play the file.
//you may want to validate an auth token, or some other
//user validation logic that's important to your system here
if file.is_downloadable
AWS::S3::Base.establish_connection!( )
url = AWS::S3::S3Object.url_for(file.path, YOUR_BUCKET, :expires_in => 1.minutes)
redirect_to url
end
//file is not downloadable
//return a forbidden message
raise ActionController::Forbidden
end
end
So, when the user clicks a download-button in the app, it should call this getFile-method? And it will check if the file is downloadable (in model) before downloading the object? But my issue is: if the file is not public (downloadable) in s3, then it won't play in the app? The users should hear the audiofile in the app, and also be restricted download-access if the users declare the file as not downloadable. But if I make it public, anyone with the link can download it, right?
– Marius W
Nov 25 '18 at 10:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462914%2faccessing-aws-s3-files-only-from-react-native-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The code is pretty crude as I spend most of my time in Node + Go, but I think it gets the primary point across.
You want to create an endpoint in your API to control playing files. All interaction with the file will be done through this endpoint that way you can control access to the file in any way that you want.
class SoundFileController < ActionController::Base
def getFile
file = SoundFile.get(params[:fileId])
//do some validation to determine if you can play the file.
//you may want to validate an auth token, or some other
//user validation logic that's important to your system here
if file.is_downloadable
AWS::S3::Base.establish_connection!( )
url = AWS::S3::S3Object.url_for(file.path, YOUR_BUCKET, :expires_in => 1.minutes)
redirect_to url
end
//file is not downloadable
//return a forbidden message
raise ActionController::Forbidden
end
end
So, when the user clicks a download-button in the app, it should call this getFile-method? And it will check if the file is downloadable (in model) before downloading the object? But my issue is: if the file is not public (downloadable) in s3, then it won't play in the app? The users should hear the audiofile in the app, and also be restricted download-access if the users declare the file as not downloadable. But if I make it public, anyone with the link can download it, right?
– Marius W
Nov 25 '18 at 10:29
add a comment |
The code is pretty crude as I spend most of my time in Node + Go, but I think it gets the primary point across.
You want to create an endpoint in your API to control playing files. All interaction with the file will be done through this endpoint that way you can control access to the file in any way that you want.
class SoundFileController < ActionController::Base
def getFile
file = SoundFile.get(params[:fileId])
//do some validation to determine if you can play the file.
//you may want to validate an auth token, or some other
//user validation logic that's important to your system here
if file.is_downloadable
AWS::S3::Base.establish_connection!( )
url = AWS::S3::S3Object.url_for(file.path, YOUR_BUCKET, :expires_in => 1.minutes)
redirect_to url
end
//file is not downloadable
//return a forbidden message
raise ActionController::Forbidden
end
end
So, when the user clicks a download-button in the app, it should call this getFile-method? And it will check if the file is downloadable (in model) before downloading the object? But my issue is: if the file is not public (downloadable) in s3, then it won't play in the app? The users should hear the audiofile in the app, and also be restricted download-access if the users declare the file as not downloadable. But if I make it public, anyone with the link can download it, right?
– Marius W
Nov 25 '18 at 10:29
add a comment |
The code is pretty crude as I spend most of my time in Node + Go, but I think it gets the primary point across.
You want to create an endpoint in your API to control playing files. All interaction with the file will be done through this endpoint that way you can control access to the file in any way that you want.
class SoundFileController < ActionController::Base
def getFile
file = SoundFile.get(params[:fileId])
//do some validation to determine if you can play the file.
//you may want to validate an auth token, or some other
//user validation logic that's important to your system here
if file.is_downloadable
AWS::S3::Base.establish_connection!( )
url = AWS::S3::S3Object.url_for(file.path, YOUR_BUCKET, :expires_in => 1.minutes)
redirect_to url
end
//file is not downloadable
//return a forbidden message
raise ActionController::Forbidden
end
end
The code is pretty crude as I spend most of my time in Node + Go, but I think it gets the primary point across.
You want to create an endpoint in your API to control playing files. All interaction with the file will be done through this endpoint that way you can control access to the file in any way that you want.
class SoundFileController < ActionController::Base
def getFile
file = SoundFile.get(params[:fileId])
//do some validation to determine if you can play the file.
//you may want to validate an auth token, or some other
//user validation logic that's important to your system here
if file.is_downloadable
AWS::S3::Base.establish_connection!( )
url = AWS::S3::S3Object.url_for(file.path, YOUR_BUCKET, :expires_in => 1.minutes)
redirect_to url
end
//file is not downloadable
//return a forbidden message
raise ActionController::Forbidden
end
end
answered Nov 25 '18 at 6:27
TravisTravis
3,92912335
3,92912335
So, when the user clicks a download-button in the app, it should call this getFile-method? And it will check if the file is downloadable (in model) before downloading the object? But my issue is: if the file is not public (downloadable) in s3, then it won't play in the app? The users should hear the audiofile in the app, and also be restricted download-access if the users declare the file as not downloadable. But if I make it public, anyone with the link can download it, right?
– Marius W
Nov 25 '18 at 10:29
add a comment |
So, when the user clicks a download-button in the app, it should call this getFile-method? And it will check if the file is downloadable (in model) before downloading the object? But my issue is: if the file is not public (downloadable) in s3, then it won't play in the app? The users should hear the audiofile in the app, and also be restricted download-access if the users declare the file as not downloadable. But if I make it public, anyone with the link can download it, right?
– Marius W
Nov 25 '18 at 10:29
So, when the user clicks a download-button in the app, it should call this getFile-method? And it will check if the file is downloadable (in model) before downloading the object? But my issue is: if the file is not public (downloadable) in s3, then it won't play in the app? The users should hear the audiofile in the app, and also be restricted download-access if the users declare the file as not downloadable. But if I make it public, anyone with the link can download it, right?
– Marius W
Nov 25 '18 at 10:29
So, when the user clicks a download-button in the app, it should call this getFile-method? And it will check if the file is downloadable (in model) before downloading the object? But my issue is: if the file is not public (downloadable) in s3, then it won't play in the app? The users should hear the audiofile in the app, and also be restricted download-access if the users declare the file as not downloadable. But if I make it public, anyone with the link can download it, right?
– Marius W
Nov 25 '18 at 10:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462914%2faccessing-aws-s3-files-only-from-react-native-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown