Dan Walmsley
Dan Walmsley

Reputation: 2821

Uploading a file to a perl cgi script from Javascript/jquery

I want to send a file to a server using Javascript on the client end and a perl cgi script on the server. And well I don't know where to start.

This is what I understand that I need to do; open the file read it, pass it to the server as the request body, pull the file out of the request body at the server end.

So any one know a good way to do this? also if I have got any of the basics wrong please let me know.

Upvotes: 0

Views: 1816

Answers (1)

collapsar
collapsar

Reputation: 17238

I'd recommend using jquery client-side and CGI.pm server-side. The following resources will provide details:

  • Tutorial on how to exploit the File API of modern browsers (with or without drag-and-drop metaphor). To see whether or not your targeted user agents support this technique, look here and here.
  • JQuery method to issue a POST request the data attribute will be reader.result in your case (adopting the variable names from the code examples in the linked tutorial). just keep in mind to call reader.readAsText to make the file contents available to javascript.
  • processing uploaded files with the perl module CGI.pm as part of a cgi script.

drop a comment if you need more support to get your job done. the explanations and the sample code in the cited docs are actually pretty good. Also have a look at the answer to the question Quentin ref'ed if you haven't yet done so. regards

Upvotes: 1

Related Questions