Code Monkey home page Code Monkey logo

Comments (9)

jmathai avatar jmathai commented on July 30, 2024

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.

akirasan avatar akirasan commented on July 30, 2024

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.

akirasan avatar akirasan commented on July 30, 2024

No code its implemented for upload image,.... :(

I've coding part of the solution and I upload successfully to my trovebox.

from openphoto-python.

sneakypete81 avatar sneakypete81 commented on July 30, 2024

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.

walkah avatar walkah commented on July 30, 2024

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.

jmathai avatar jmathai commented on July 30, 2024

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

akirasan avatar akirasan commented on July 30, 2024

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.

sneakypete81 avatar sneakypete81 commented on July 30, 2024

Closed by #19 - thanks for your help @akirasan.

from openphoto-python.

akirasan avatar akirasan commented on July 30, 2024

Wow,...that's work perfectly!!!!,...great job!!!.

from openphoto-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.