tags:

views:

84

answers:

1

I need to change the below code to pass a file to a django request.Files object. Currently I pass the file location to django and allow it to open the file, unfortunately due to new ridiculous set in stone network restrictions django will no longer have access to anything outside of it's server.

The parameters I'm passing come from a variety of html text inputs and a file select.

I'm keen to change very little but if there is no other way...

jQuery.get(importUrl,{"file":fileInputData,"dir":dirInputData,"year":thisSurvey,"import":thisImport,"startDate":startDate,"endDate":endDate},function(data)
{
     jQuery.jGrowl(data,{sticky:true,header:"Import Result"});
});
+1  A: 

You cannot upload files with Ajax, there are scripts around to do this but they use an iframe to submit the data (a real form submit occurs inside it). See http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery

I don't really know what you mean by "django will no longer have access to anything outside of it's server." The restriction on file uploads is to keep applications from reading and writing files onto client's computers. Essentially all uploads must come from a real <input type="file" name="file">. To access the data of an uploaded file in Django you use request.FILES['name_of_the_file_input'].

Lincoln B
"django will no longer have access to anything outside of it's server." on the company network, nothing to do with Django but to do with my corporations new policies.
danspants
The iframe solution is fine, but it will require fundamental changes to my code which is rather irritating. I was really hoping to avoid it. Ah well.
danspants