0

I am currently working on a project that is requiring me to use AngularJS's $http.post to upload Base64 encoded file contents to a server, where the file contents will be converted and saved to a remote repository.

The file that I am uploading is about 2.31 MB, yet after the server receives the file contents through the $http.post method, the file contents are only 68 K in size! What happened?

I am pretty sure that, because my file contents are in Base64 format, I am not having an issue with string termination due to embedded nulls, am I?

I am mostly wondering if there is a byte limit to the $http.post method. I havn't found my answer anywhere else.

Should I chop my file contents up, tell the server that I am starting an upload, do multiple upload chucks to the server, and then tell the server when I am done?

WebWanderer
  • 10,380
  • 3
  • 32
  • 51
  • Interesting look @scragar. I'll be sure to check out `maxAllowedContentLength`. But, to clear things up, the file contents are 2.31 MB after base64 encoding, and the server receives the file contents in base64 encoding as well, so the content that the server receives should also be 2.31 MB, but they are 68 K instead. – WebWanderer Jul 21 '14 at 13:35
  • Where did the other comments go...? – WebWanderer Jul 21 '14 at 13:37
  • The author deleted it. – afaolek Jul 21 '14 at 14:01

2 Answers2

2

Silly me...

So, the entire 2.31 MB were coming across to the server, yet I was truncating the file contents by only allocating a buffer that was just under 65K, the max limit to a TCP/IP packet. Simply enough, I just need to make my buffer size dynamic to the incoming packet, after the packet has been reconstructed. Thanks for all the help guys.

WebWanderer
  • 10,380
  • 3
  • 32
  • 51
1

I'm quoting this from the third answer in this question:

Maybe you have an & in your content variable. Then everything after that would be stripped after that.

So maybe in the base64-encoded file, there's an & somewhere alone the 68000th character chopping off the rest of the file since it thinks there is another request attached.

Something like: http://www.example.com?post=324b6bjgj5jhg&fgdhgtuhuf will present $_GET['post'] as 324b6bjgj5jhg rather than 324b6bjgj5jhg&fgdhgtuhuf. The & makes it think there's another variable. I know this is a GET request but I guess something similar could be happening in POST, too.

Community
  • 1
  • 1
afaolek
  • 8,452
  • 13
  • 45
  • 60
  • Your talking about a string terminator in a base64 encoded string? Interesting. I'll check it out. Thanks. – WebWanderer Jul 21 '14 at 13:37
  • @WebWanderer If you suspect that's the problem, you can check this [question](http://stackoverflow.com/questions/2231810/escaping-jquery-data-being-sent-via-post) on how to mitigate it. Someone mentioned using JavaScript's [escape](http://www.w3schools.com/jsref/jsref_escape.asp), although it's deprecated and then you will have to 'unescape' when you are retrieving the data. But try to check out the question if you suspect so. – afaolek Jul 21 '14 at 14:01
  • Wait, like I said, this is base64 encoded. An `&` isn't a base64 character, so that shouldn't ever happen. – WebWanderer Jul 21 '14 at 14:34