I have an external application uploading a file to my rails web app. (Developed on Heroku, but that's not completely relevant)
I need to upload that file to AWS. I've successfully connected to AWS with rails, but I can't figure out how to access the file that was uploaded.
I know I need to do File.open({path to file}), then pass the File to AWS
I forgot to set the multipart enctype in my test external application...if anyone else has this same problem this code should work:
AWS::S3::S3Object.store('{filename.ext_for_aws}',params[:{name_from_post}],'{bucket}')
Related
I'm working with simple rails 6 application and use active storage with Amazon S3, it works fine. But after I deploy anything all of my pic URLs have 500 errors. But my attachments still in the database and all my pictures stay untouched on S3 and URLs to rails/active_storage/representations are the very same before deploy when all was fine.
All credentials are encrypted in credentials.yml.enc and master.key in the config folder and if rails can start and upload a file into s3 in this way it works fine?
Here how I display picture, nothing special:
image_tag #product.images.first.variant(resize: "420x")
I guess it's something with some secret tokens which augmentates application but couldn't find anything relevant. Can someone advise at least where can be a problem?
I would like to create some_javascript_file.js after a user submits a form and save this file in the public directory of my app.
When testing this localy I can simply use File.new("./public/some_javascript_file.js", "w") to accomplish this but this solution doesn't work when the app is deployed to Heroku.
Please would you have any suggestions? Thank you
This is because of how Heroku works. Basically, as stated in the docs, the filesystem is ephemeral and you can't rely on it. If you want persistence, you should upload this JS file to some external service, such as AWS S3. Or you might want to deploy your app to a different environment, such as self-managed VPS, where filesystem is real and your file won't disappear.
Hi I am a ROR developer and developing an ROR application where user can upload file and share the URL to download.
I am using carrierwave for file upload and storing the file in my application (not in AWS).
I want to give permission for the user to access the upload file only for a certain period of time (for ex:1 hour).
please help me to achieve this without creating any cron jobs or before_filter method?
I found AWS has default feature for this but I am not storing the file in AWS S3. I am storing it in my local application folder, so please guide me how I can achieve this.
Does anyone have any sample code (preferrably in rails) that uploads to s3, using s3's servers.
Again, uploading directly to s3, where the actual upload/streaming is also preformed on amazon's servers.
Requirements:
Plupload, jQuery
Idea:
Authorize Upload via your app (sign it on server-side)
Use the signed request to upload the file to S3
Notify your app that the upload is done
Check whether S3 has received the file
I posted the code as a gist at https://gist.github.com/759939, it misses commments and you might run into some issues due to missing methods (had to rip it from our codebase).
stored_file.rb contains a model for your DB. Has many of paperclips helper methods inlined (which we used before we switched to direct upload to S3).
I hope you can use it as a sample to get your stuff running.
If you are using Rails 3, please check out my sample projects:
Sample project using Rails 3, Flash and MooTools-based FancyUploader to upload directly to S3: https://github.com/iwasrobbed/Rails3-S3-Uploader-FancyUploader
Sample project using Rails 3, Flash/Silverlight/GoogleGears/BrowserPlus and jQuery-based Plupload to upload directly to S3: https://github.com/iwasrobbed/Rails3-S3-Uploader-Plupload
To simply copy files, this is easy to use:
Smart Copy Script into S3
Amazon wrote a Ruby library for the S3 REST API. I haven't used it yet.
http://amazon.rubyforge.org/
I'm using paperclip to upload some text/csv files to an S3 bucket.
I need to edit those files occasionally. How can I edit and re-save those?
Before using S3, I was just using File.open for saving the files, but that throws a "No such file or directory" error now.
File.open opens a file system object. To access S3 you need to connect to the S3 server and issue commands, such as GET.
There are some gems available from the Amazon developer's site which may help.
http://aws.amazon.com/ruby/