Ruby on Rails Wednesday, January 25, 2017

> On Jan 25, 2017, at 7:00 AM, Paramnoor Singh <paramnoor.intersoft@gmail.com> wrote:
>
>
> Problem: I have use the net/http code for uploading the '.doc', '.docx', '.pdf' and images files on dropbox. But I getting the issues like:
>
> 1.invalid byte sequence in UTF 8
> 2. Now while the file is uploading but it not uploading the content and even it uploading as a corrupt file.
>
> Below I writing my code to upload the file on dropbox. Please help me.
>
> Code:
>
> uri = URI.parse("https://content.dropboxapi.com/2/files/upload")
> request = Net::HTTP::Post.new(uri)
> request.content_type = "application/octet-stream"
> request["Authorization"] = "Bearer #{$acess_token}"
> request["Dropbox-Api-Arg"] = "{\"path\":\"/Sass-for-Web-Designers.pdf\"}"
> request.body = ""
> request.body << File.open("app/assets/images/categoryImages/Sass-for-Web-Designers.pdf").read

This line is opening the file as a UTF-8 string, which it most likely is not. Read up on File.open, particularly the various flags you can pass to it to ensure that the file is being opened as a binary, not a text file.

Walter

> #request.body << file.content
> #file.close
>

No comments:

Post a Comment