# Upload via API leads to missing plus signs in HTTP-Body

**URL:** <https://www.ruby-forum.com/t/upload-via-api-leads-to-missing-plus-signs-in-http-body/158412>\
**Category:** Rails\
**Created:** [January 23, 2009, 1:22am UTC](https://www.ruby-forum.com/t/upload-via-api-leads-to-missing-plus-signs-in-http-body/158412 "2009-01-23T01:22:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TKAB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/779978/32.png) [@TKAB](https://www.ruby-forum.com/u/TKAB)\
**Post date:** [January 23, 2009, 1:22am UTC](https://www.ruby-forum.com/t/upload-via-api-leads-to-missing-plus-signs-in-http-body/158412/1 "2009-01-23T01:22:33Z")

</div>

Hi!

I’m developing a Rails-app that needs to take images from a separate  
program. I managed to upload base64 encoded images via HTTP-Post-  
Request (Cocoa), the HTTP-Body looks like (base64-data is shortened)  
this:

“filename=Pic1.jpg&content\_type=image/jpeg&data=/9j/4AAQSkZJRgABAQECeUJ  
+woRAD/4gxYSU”

When I access the data via params[:data] in my controller, all the  
plus signs are gone and substituted with spaces. I checked the  
outgoing data of the separate program with a sniffer and it contains  
the plus signs, so the substitution must take place somewhere on the  
server.

Does anybody have an idea what causes this behaviour?

Thanks,  
Thomas

---

<div class="post-metadata">

**Author:** ![TKAB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/779978/32.png) [@TKAB](https://www.ruby-forum.com/u/TKAB)\
**Post date:** [January 23, 2009, 1:24am UTC](https://www.ruby-forum.com/t/upload-via-api-leads-to-missing-plus-signs-in-http-body/158412/2 "2009-01-23T01:24:53Z")

</div>

On Jan 22, 11:00 pm, TKAB [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> When I access the data via params[:data] in my controller, all the  
> plus signs are gone and substituted with spaces. I checked the  
> outgoing data of the separate program with a sniffer and it contains  
> the plus signs, so the substitution must take place somewhere on the  
> server.

The standards dictate that with application/x-www-form-urlencoded  
data (the default;  
[Forms in HTML documents](http://www.w3.org/TR/html401/interact/forms.html#h-17.13.3.3))  
spaces are encoded by + signs, so the server is doing the correct  
thing by turning them into spaces.

Fred

---

<div class="post-metadata">

**Author:** ![TKAB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/779978/32.png) [@TKAB](https://www.ruby-forum.com/u/TKAB)\
**Post date:** [January 23, 2009, 9:19am UTC](https://www.ruby-forum.com/t/upload-via-api-leads-to-missing-plus-signs-in-http-body/158412/3 "2009-01-23T09:19:21Z")

</div>

Thank you very much, I was completely unaware of that.  
So it would be a better idea to imitate a form upload and set the  
Content-Type to multipart/form-data? Or is there any other way?

---

<div class="post-metadata">

**Author:** ![TKAB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/779978/32.png) [@TKAB](https://www.ruby-forum.com/u/TKAB)\
**Post date:** [January 23, 2009, 1:01pm UTC](https://www.ruby-forum.com/t/upload-via-api-leads-to-missing-plus-signs-in-http-body/158412/4 "2009-01-23T13:01:09Z")

</div>

On 23 Jan 2009, at 08:18, TKAB wrote:

> Thank you very much, I was completely unaware of that.  
> So it would be a better idea to imitate a form upload and set the  
> Content-Type to multipart/form-data?  
> Certainly an option  
> Or is there any other way?

You could replace + signs with what ever the correct % escape sequence  
is, but the multipart/form-data route is probably simpler.

Fred

---

<div class="post-metadata">

**Author:** ![TKAB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/779978/32.png) [@TKAB](https://www.ruby-forum.com/u/TKAB)\
**Post date:** [January 23, 2009, 4:47pm UTC](https://www.ruby-forum.com/t/upload-via-api-leads-to-missing-plus-signs-in-http-body/158412/5 "2009-01-23T16:47:52Z")

</div>

OK, I understand.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![TKAB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/779978/32.png) [@TKAB](https://www.ruby-forum.com/u/TKAB)\
**Post date:** [January 23, 2009, 10:47pm UTC](https://www.ruby-forum.com/t/upload-via-api-leads-to-missing-plus-signs-in-http-body/158412/6 "2009-01-23T22:47:03Z")

</div>

TKAB wrote:

> OK, I understand.
> 
> Thanks for your help!

> **[Base64 | URL applications](https://en.wikipedia.org/wiki/Base64#URL_applications)**
>
> Base64 encoding can be helpful when fairly lengthy identifying information is used in an HTTP environment. For example, a database persistence framework for Java objects might use Base64 encoding to encode a relatively large unique id (generally 128-bit UUIDs) into a string for use as an HTTP parameter in HTTP forms or HTTP GET URLs. Also, many applications need to encode binary data in a way that is convenient for inclusion in URLs, including in hidden web form fields, and Base64 is a convenient...

This might help. See the section on an alternative base64 that is safe  
for URL encoding.
