Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading broken files to Amazon S3 #31

Closed
Mohakjuneja opened this issue Apr 6, 2016 · 8 comments
Closed

Uploading broken files to Amazon S3 #31

Mohakjuneja opened this issue Apr 6, 2016 · 8 comments

Comments

@Mohakjuneja
Copy link

I'm using mongoid along with carrierwave to upload files using JSON API. My controller method looks like this-

def create
    content = Content.new(content_params)     
    content.user_id = current_user.id 
    content.asset_type = content.asset.file.extension      
    if content.save      
      render json: content, status: 201, location: [:api, content] 
      ProcessAsset.perform_async(content.id.to_s) unless content.asset_type != 'pdf'
    else
      render json: { errors: content.errors }, status: 422
    end
end

Model

class Content

  include Mongoid::Document
  include Mongoid::Timestamps

  before_create :set_base_price

  mount_base64_uploader :asset, AssetUploader
  # more code
end


While the whole process works great, the file uploaded to S3 (pdf in this case) has no content in it.
I believe this has something to do with StringIO being used to read the file from the system. It sets the content_type to plain/text. This is confirmed when I download the pdf and try to open it on my system.

Here's my json I'm using to upload -
{
"content": {
"campus" : "569df3c4be84c511c0000001",
"course" : "569dfe1cbe84c511c0000006",
"subject" : "56a0c4debe84c50d2f000006",
"batch" : "2015",
"title" : "RipAndSave",
"asset": "data:application/pdf;base64,L2hvbWUvbW9qby9Eb3dubG9hZHMvc2FtcGxlLnBkZg=="
}
}

I'm using Rails 4.2, Mongoid 5.1

Can you help?

@Mohakjuneja
Copy link
Author

@lebedev-yury Have you been able to take a look at this yet?

@y9v
Copy link
Owner

y9v commented May 7, 2016

Hi! You are experiencing the problem only with pdf file uploads, or with other file types too?

@Mohakjuneja
Copy link
Author

It's the same for images too. The content type saved is text/html
On 7 May 2016 23:39, "Yury Lebedev" notifications@github.com wrote:

Hi! You are experiencing the problem only with pdf file uploads, or with
other file types too?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#31 (comment)

@y9v
Copy link
Owner

y9v commented May 12, 2016

You mean that when you open the url to the uploaded file, it shows the file as plain in the browser? If yes, this might be a problem with incorrect content-disposition, set in your amazon s3

@y9v y9v closed this as completed Jun 18, 2016
@Mohakjuneja
Copy link
Author

Mohakjuneja commented Jul 16, 2016

Hey @lebedev-yury ,
I'm publishing a sample repository to reproduce the above error. The storage, both file system and remote (S3) set the content type to text/plain. You can fork the repository to test it. Also, I don't set content-disposition anywhere. Please let me know if I'm doing it wrong.
Thanks

https://github.com/Mohakjuneja/Base64upload

@y9v
Copy link
Owner

y9v commented Jul 18, 2016

The base64 string when decoded is the absolute path to the original file on local machine.

I think you misunderstand the concept of base64 encoded uploads. How do you think your web application would get the file contents from your local machine, by just having the address?

Base64 string should contain the contents of the file, that you want to upload, encoded in base64 string

@Mohakjuneja
Copy link
Author

Hi Yuri,
I apologise. I figured it myself just a few hours after writing to you. I'm
sorry about the trouble. I was fixated on it for over a week when I wrote
to you. Thank you for taking out time to see it!
On 18 Jul 2016 12:33, "Yury Lebedev" notifications@github.com wrote:

The base64 string when decoded is the absolute path to the original file
on local machine.

I think you misunderstand the concept of base64 encoded uploads. How do
you think your web application would get the file contents from your local
machine, by just having the address?

Base64 string should contain the contents of the file, that you want to
upload, encoded in base64 string


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#31 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFBQvvn_I2ZxdJJb0hD8UBw6LAS5GP0Tks5qWyVUgaJpZM4IBgGb
.

@Mohakjuneja
Copy link
Author

Hi @lebedev-yury ,
I'm trying to upload multiple files(20), with an average size of 700 KB using careerwave-base64 but my request times out. Is it suitable to upload them with this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants