# Upload a big file using Sketchup::Http::Request

**URL:** <https://forums.sketchup.com/t/upload-a-big-file-using-sketchup-request/85583>\
**Category:** Ruby API\
**Created:** [January 16, 2019, 12:35pm UTC](https://forums.sketchup.com/t/upload-a-big-file-using-sketchup-request/85583 "2019-01-16T12:35:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KarenAvdalyan](https://avatars.discourse-cdn.com/v4/letter/k/cab0a1/32.png) [@KarenAvdalyan](https://forums.sketchup.com/u/KarenAvdalyan)\
**Post date:** [January 16, 2019, 12:35pm UTC](https://forums.sketchup.com/t/upload-a-big-file-using-sketchup-request/85583/1 "2019-01-16T12:35:16Z")

</div>

I try to upload a file using `Sketchup::Http::Request` class. I use the code bellow:

```
body << "--" + boundary + "\r\n" +
"Content-Disposition: form-data; name=\"" + param_name.to_s + "\"; filename=\"" + filename + "\"\r\n" + 
"Content-Type: #{@content_type}\r\n\r\n"
body << File.read(filepath)
body << "\r\n--#{boundary}--\r\n"
 
req = Sketchup::Http::Request.new( Constants::SiteURL, Sketchup::Http::POST)
req.body = body.join
http = Net::HTTP.new(url.host, url.port)
http.read_timeout=3600

req.start do |request, response|
  #puts "body: #{response.body}"
end

```

Actually it works fine when I try to upload a small file, but when the file is a little big (I’ve tried for 4 mb zip file)  
the file is uploaded to the cloud but it’s size is small than it should be (only 2 kb) and the zip is corrupted.  
I’ve searched a little and seems the problem is connected with `File.read(filepath)`

I’ve found another alternative using

```
req = Net::HTTP::Post.new(url.path)

```

and it solved my problem because it has

```
req.body_stream

```

field and I could make an upload in this way

```
stream = File.open(filepath,"rb")
streams << stream
parts << StreamPart.new(stream, File.size(filepath))
parts << StringPart.new( "\r\n--" + boundary + "--\r\n" )
post_stream = MultipartStream.new( parts )
req.body_stream = post_stream

```

But I want to use `Sketchup::Http::Request` because it has

```
 set_upload_progress_callback

```

method which I want to use.

So please help me to understand  
how can I upload a “big” file(several mb) with `Sketchup::Http::Request` in a correct way

---

<div class="post-metadata">

**Author:** ![Aerilius](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@Aerilius](https://forums.sketchup.com/u/Aerilius)\
**Post date:** [January 16, 2019, 1:20pm UTC](https://forums.sketchup.com/t/upload-a-big-file-using-sketchup-request/85583/2 "2019-01-16T13:20:18Z")

</div>

Are you trying to read a binary file in text mode ([`File.read`](https://ruby-doc.org/core-2.6/IO.html#method-c-read) without mode specified) ?

If you are _not_ using a system other than Windows, then you need to pay attention to the `"rb"` parameter, because Windows corrupts binary data when it reads them in text mode.
