I 'm implementing file upload app. A client can be both web and desktop
application. I have tested using html form and receive file via
request.FILES, it success. For desktop app, I use python urllib which data
can be encoded into python dictionary (urllib.urlencode) and send it to my
django web with urllib.urlopen. What different is, I found file at
request.POST?!?
import os
import urllib
def sendbin(file):
#split path
n=os.path.split(file)
#get it name
name = n[len(n)-1]
print name
#open binary file
file = open(file,'rb')
#encode data as bosy of http request
data = urllib.urlencode({'name':name, 'file': file.read()})
file.close()
#tranmitt it
f = urllib.urlopen("http://127.0.0.1:8000/test/",data)
#read response
f.read()
#close connect
f.close()
Regards
chatchai
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---