How to write received zip file content using ruby on rails

user1011792

I am reading some zip file from disk through a rails application and sending it to another rails application, so in the receiver side the value of params["file"] is

#<ActionDispatch::Http::UploadedFile:0x00000008d66bb0
 @content_type="application/zip",
 @headers=
  "Content-Disposition: form-data; name=\"file\"; filename=\"test.zip\"\r\nContent-Length: 2706\r\nContent-Type: application/zip\r\nContent-Transfer-Encoding: binary\r\n",
 @original_filename="test.zip",
 @tempfile=#<File:/tmp/RackMultipart20141221-3194-1cq6k5b>>

I want to download this zipped file to receiver disk, so I guess I need read its data and write it, so I do the fllowing:

File.open("filepath", "w") do |f|
 f.write(params["file"].tempfile.read)
end

however I get the error message

Encoding::UndefinedConversionError ("\xF4" from ASCII-8BIT to UTF-8)

I tried several solutions to this encoding issue, but all in vain.

So how can I download a received zip file ? Thanks

Uri Agassi

Try:

File.open("filepath", "wb") do |f|
 f.write(params["file"].tempfile.read)
end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to write the content of external .js files in a js.haml file (Ruby on Rails)

From Dev

How to write a zip file using Haskell LibZip?

From Dev

How to write a zip file using Haskell LibZip?

From Dev

How to write this in ruby on rails?

From Dev

Write to a ruby file using ruby

From Java

How to write to file in Ruby?

From Dev

How to write a file with ruby?

From Dev

How to write zip file into httpresponse

From Dev

How to write to file the data received in an infinite loop

From Dev

How to write testcase in Ruby on Rails

From Dev

How to read a text file content and write to another text file after formatting the text file content using Java?

From Dev

How to write a big ISO file into a few disks for using its content?

From Dev

How to write BytesWritable content to a file?

From Dev

How to write the rendered content into a file

From Dev

How to write the rendered content into a file

From Dev

ruby on rails - how to read json file using ajax?

From Dev

How to format the table in rtf file while using it at ruby on rails?

From Dev

Using Tempfile to create a zip file in rails

From Dev

how to extract zip file content into sd card?

From Dev

how to extract zip file content into sd card?

From Dev

How to write and include regular ruby classes in rails

From Dev

How to write trigger in ruby on rails on creation

From Dev

Ruby On Rails: How to write yml configurations in a file when deploying with Capistrano 3?

From Dev

How to read zip file content without unzipping (in compressed format) using Python

From Dev

Selenium Webdriver using Ruby: write text to file

From Dev

How to implement multiple file upload and how to download the files with same id as a zip using carrierwave rails?

From Dev

Can't upload zip files using ruby on rails and paperclip gem

From Dev

How to read a text file and write the content into another text file using stdio.h C library

From Dev

How to write PDF content in a string to a file in java?

Related Related

  1. 1

    How to write the content of external .js files in a js.haml file (Ruby on Rails)

  2. 2

    How to write a zip file using Haskell LibZip?

  3. 3

    How to write a zip file using Haskell LibZip?

  4. 4

    How to write this in ruby on rails?

  5. 5

    Write to a ruby file using ruby

  6. 6

    How to write to file in Ruby?

  7. 7

    How to write a file with ruby?

  8. 8

    How to write zip file into httpresponse

  9. 9

    How to write to file the data received in an infinite loop

  10. 10

    How to write testcase in Ruby on Rails

  11. 11

    How to read a text file content and write to another text file after formatting the text file content using Java?

  12. 12

    How to write a big ISO file into a few disks for using its content?

  13. 13

    How to write BytesWritable content to a file?

  14. 14

    How to write the rendered content into a file

  15. 15

    How to write the rendered content into a file

  16. 16

    ruby on rails - how to read json file using ajax?

  17. 17

    How to format the table in rtf file while using it at ruby on rails?

  18. 18

    Using Tempfile to create a zip file in rails

  19. 19

    how to extract zip file content into sd card?

  20. 20

    how to extract zip file content into sd card?

  21. 21

    How to write and include regular ruby classes in rails

  22. 22

    How to write trigger in ruby on rails on creation

  23. 23

    Ruby On Rails: How to write yml configurations in a file when deploying with Capistrano 3?

  24. 24

    How to read zip file content without unzipping (in compressed format) using Python

  25. 25

    Selenium Webdriver using Ruby: write text to file

  26. 26

    How to implement multiple file upload and how to download the files with same id as a zip using carrierwave rails?

  27. 27

    Can't upload zip files using ruby on rails and paperclip gem

  28. 28

    How to read a text file and write the content into another text file using stdio.h C library

  29. 29

    How to write PDF content in a string to a file in java?

HotTag

Archive