0

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 ?

<script type='text/javascript'>
$(document).ready(function() {

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"});
    }
);
});
</script>

1 Answer 1

2

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 How can I upload files asynchronously?

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'].

Sign up to request clarification or add additional context in comments.

2 Comments

"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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.