We help IT Professionals succeed at work.
Get Started

send a very long string buffer as a file to the server using JavaScript

omer d
omer d asked
Last Modified: 2015-04-13

I've a client in JavaScript and a server in Django,
I'm trying to send a very long html text buffer (more than 20,000 characters) to the server.
I think that the best way is to convert is to a file in the client and send it as a file to the server,
but i didn't find a way to do it.

first I tried using post:
var string = escape(html_code);
var params = "value=" + string + '';
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-length", params.length);
xhr.setRequestHeader("Connection", "close");

Open in new window

but it worked for me only for up to ~10,000 bytes:

than I saw that there is a way to send it using blob:
var blob = new Blob([string], {type: 'text/html'});

Open in new window

But I didn't find a way to get it to work / get it on the server..

also tried:
var xmlDoc = parser.parseFromString(string, "text/xml");

Open in new window

any idea?
Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE