Comments (9)
I believe a local file needs to be prefixed with a @.
openphoto -p -X POST -H akirasan.trovebox.com -e /photo/upload.json -F 'photo=@/mnt/ksi2t/scripts/DSC_8422.JPG' -F 'tags=test'
from openphoto-python.
Yes, I try with the @ but the error is the same. I'm testing differents parameters like "--encode" at the end of the command line, but not work,...
from openphoto-python.
No code its implemented for upload image,.... :(
I've coding part of the solution and I upload successfully to my trovebox.
from openphoto-python.
One option is to Base64 encode the picture data. Something like:
import base64
encoded_photo = base64.b64encode(open(photo_file, "rb").read())
This is implemented in the #13 PR.
from openphoto-python.
let me do another look through PR13 and we'll get that in and closed and hopefully clear this one up in the process! thanks @sneakypete81
from openphoto-python.
@akirasan If you have code to do the multipart upload then submit that in a separate pull request.
Thanks @akirasan @sneakypete81 @walkah
from openphoto-python.
Hi, here you are (I can't open a pull request):
def post(self, endpoint, params={}):
url = urlparse.urlunparse(('http', self.host, endpoint, '', '', ''))
if self.consumer_key:
consumer = oauth.Consumer(self.consumer_key, self.consumer_secret)
token = oauth.Token(self.token, self.token_secret)
# ensure utf-8 encoding for all values.
params = dict([(k, v.encode('utf-8')
if type(v) is types.UnicodeType else v)
for (k, v) in params.items()])
files = [("photo", 'test.jpg', open('/mnt/ksi2t/scripts/test.jpg', 'rb').read())]
import mimetools
import mimetypes
BOUNDARY = mimetools.choose_boundary()
CRLF = '\r\n'
L = []
for (key, value) in params.items():
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"' % key)
L.append('')
L.append(value)
for (key, filename, value) in files:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
L.append('Content-Type: %s' % mimetypes.guess_type(filename)[0] or 'application/octet-stream')
L.append('')
L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
headers = {'Content-Type': content_type, 'Content-Length': str(len(body))}
client = oauth.Client(consumer, token)
headers, content = client.request(url, "POST", body, headers)
return content
Obviously my level in Python is very low, for this reason I hardcode the "file" path on:
files = [("photo", 'test.jpg', open('/mnt/ksi2t/scripts/test.jpg', 'rb').read())]
...and when we call the command is not needed inform the path (this code is for only test :) ):
openphoto -p -X POST -H akirasan.trovebox.com -e /photo/upload.json
from openphoto-python.
Closed by #19 - thanks for your help @akirasan.
from openphoto-python.
Wow,...that's work perfectly!!!!,...great job!!!.
from openphoto-python.
Related Issues (20)
- Provide the necessary command-line steps to create OAuth tokens HOT 1
- Make the library more Pythonic HOT 7
- Delete methods should return boolean HOT 2
- Rename to Trovebox HOT 6
- Submit to PyPI
- Python 3 Support HOT 2
- Add support for TravisCI HOT 5
- Remove redundant tag/create API endpoint HOT 2
- Retry if a request fails HOT 1
- More unit tests
- accept use of self-signed ssl certificate HOT 6
- doesn't work with https HOT 2
- CLI does not perform tilde expansion
- error with StringIO cannot read config_file HOT 3
- Properly handle Unicode characters in post params HOT 7
- Uploading files with non ASCII characters fails HOT 5
- Support unicode parameter lists
- Validate config files
- Explicitely state a license in the code (copyright headers) of LICENSE file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openphoto-python.