keep filename while uploading an url with python response library -


i using python upload file api with

url = 'http://domain.tld/api/upload' files = {'file': open('image.jpg', 'rb')}  r = requests.post(url, files=files) 

this works , file uploaded server image.jpg. don't have local files uri instead, changed code to:

url = 'http://domain.tld/api/upload' files = {'file': urlopen('http://domain.tld/path/to/image.jpg')}  r = requests.post(url, files=files) 

the image uploaded sucessfully not preserve it's name , stored 'file' (without extension). question is, how can upload url while keeping it's filename (of course without downloading first)

you can pass name:

 files = {'name': ('image.jpg', urlopen('http://domain.tld/path/to/image.jpg'))} 

if @ post body see variation:

content-disposition: form-data; name="file"; filename="file" 

and using code above:

content-disposition: form-data; name="name"; filename="image.jpg" 

you can see name retained in latter.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -