support individual file upload
This commit is contained in:
parent
4aa92f9e3b
commit
9413bc4a7a
1 changed files with 16 additions and 7 deletions
|
@ -453,20 +453,26 @@ class Client(object):
|
||||||
return
|
return
|
||||||
conn, c = self._conn()
|
conn, c = self._conn()
|
||||||
if args:
|
if args:
|
||||||
info = {}
|
|
||||||
data = []
|
data = []
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if os.path.exists(arg):
|
if os.path.exists(arg):
|
||||||
self.scan_file(arg)
|
|
||||||
oshash = ox.oshash(arg)
|
oshash = ox.oshash(arg)
|
||||||
info[oshash] = self.info(oshash)
|
r = self.api.findFiles({'query': {
|
||||||
|
'conditions': [{'key': 'oshash', 'value': oshash}]
|
||||||
|
}})['data']['items']
|
||||||
|
if r == 0:
|
||||||
|
self.scan_file(arg)
|
||||||
|
info = self.info(oshash)
|
||||||
|
filename = os.path.basename(arg)
|
||||||
|
r = self.api.addFile({
|
||||||
|
'id': oshash,
|
||||||
|
'info': info,
|
||||||
|
'filename': filename
|
||||||
|
})
|
||||||
data.append(oshash)
|
data.append(oshash)
|
||||||
else:
|
else:
|
||||||
data.append(arg)
|
data.append(arg)
|
||||||
files = []
|
files = []
|
||||||
if info:
|
|
||||||
post = {'info': info}
|
|
||||||
r = self.api.update(post)
|
|
||||||
else:
|
else:
|
||||||
#send empty list to get updated list of requested info/files/data
|
#send empty list to get updated list of requested info/files/data
|
||||||
post = {'info': {}}
|
post = {'info': {}}
|
||||||
|
@ -619,6 +625,7 @@ class API(ox.API):
|
||||||
data = self._json_request(url, form)
|
data = self._json_request(url, form)
|
||||||
|
|
||||||
print filename
|
print filename
|
||||||
|
result_url = data.get('url')
|
||||||
if 'uploadUrl' in data:
|
if 'uploadUrl' in data:
|
||||||
uploadUrl = data['uploadUrl']
|
uploadUrl = data['uploadUrl']
|
||||||
f = open(filename)
|
f = open(filename)
|
||||||
|
@ -684,6 +691,8 @@ class API(ox.API):
|
||||||
os.unlink(self._resume_file)
|
os.unlink(self._resume_file)
|
||||||
resume = None
|
resume = None
|
||||||
print ' ' * 80
|
print ' ' * 80
|
||||||
|
if result_url:
|
||||||
|
print result_url
|
||||||
return data and 'result' in data and data.get('result') == 1
|
return data and 'result' in data and data.get('result') == 1
|
||||||
else:
|
else:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
|
Loading…
Reference in a new issue