milesrichardson / ParsePy

A relatively up-to-date fork of ParsePy, the Python wrapper for the Parse.com API. Originally maintained by @dgrtwo
MIT License
515 stars 184 forks source link

Upload File/Images. #15

Open lullis opened 11 years ago

lullis commented 11 years ago

Right now there is no way to upload files/images to Parse through our library. We need to implement these functions on the File/Image data types.

mamcx commented 11 years ago

Any update on this? I see the file class, but not how upload the file

lullis commented 11 years ago

Nothing so far. Unfortunately I've been busy with many other projects to give attention to this one.

fraserxiong commented 10 years ago

Is there any example for updating a file/image by using ParsePy?

jasontclark commented 10 years ago

Has anyone made concessions on this feature of the library?

tc14 commented 10 years ago

Is there any update on this? or any pointer or example using ParsePy?

dgrtwo commented 10 years ago

I'll try implementing this this weekend. But of course we'd welcome push requests if anyone else solves it.

tc14 commented 10 years ago

@dgrtwo thanks for taking on this. Do you know any update on ACL/Roles support? it is listed as TODO/PLANNED action item in the ReadMe section. If there isn't any plan soon to implement this, do you have any recommendation on what is a good way/approach to do this?

jellyfangs commented 10 years ago

Facing this problem right now.

Anyone have hints on how to implement a solution?

I'm thinking reading from request.FILES and saving to Parse.File

abhimanyu1289 commented 9 years ago

I had written code to upload images/mp3 files with md5 checksum support already after realizing ParsePy does not support file uploading. This works fine for me and is being used extensively by me. All I need to do is modify it a bit and integrate it into ParsePy and create a pull request. Can I someone give me some pointers on how to do this? I see ParsePy already supports File datatype but not for modifying it I think. Is this right?

dgrtwo commented 9 years ago

That's very interesting. If you're willing to share the code in a comment, I might be able to help you get it integrated. I got stuck on this a while back (and should have put more time into it).

abhimanyu1289 commented 9 years ago

Spent some time diving into the code for the File class . I think we already have this functionality in place. The file class here already seems to be doing what I am doing. Can't we upload a file using the File class this way

file = File ('/home/user/test.mp3')
file.save()

I am a little lost here. looks like @dankrause already added File Support.

dgrtwo commented 9 years ago

Oh! I merged that pull request last month but somehow forgot (I guess I'd been associating it with a different problem). This one's on me, sorry I wasted your time.

I need to write documentation and tests for the feature before I close this issue. As discussed in the pull request the class could probably use improvement.

hugoliv commented 9 years ago

Hum, I have an issue using this #15.

2 different ways:

first

    #use local file
    fileParse = File(name="grab.jpg")
    fileParse.save()

return this (with many different image files): UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128).

The error is raised in connexion.py (line 99-100): data = data.encode('utf-8')

second

    # use distant image file
    fileParse = File(name="image.jpg", url=url_file)
    # fileParse.save() # save no needed

see attached. One click on the object in the table shows an xml file in the browser:

  ```<Error>
  <Code>AccessDenied</Code>
 <Message>Access Denied</Message>
 <RequestId>.....</RequestId>
 <HostId>.....</HostId>
 </Error>```

capture d ecran 2015-04-27 a 17 22 45 Do I miss something ?

dankrause commented 9 years ago

Yeah, it looks like the file upload code was never tested with binary files. I'll see if I can put something together tonight that properly encodes binary files before uploading.

MasterGroosha commented 9 years ago

Any improvements?

treeguard commented 8 years ago

For me, I just remove the encode("ut8-8") in connexion.py (line 99-100): data = data.encode('utf-8') to data = data and then it works

mariusmuntean commented 8 years ago

Hi,

I also get the error UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128) but in my code data = data.encode('utf-8') is on line 111 in connection.py

Any suggestions would be cool.

treeguard commented 8 years ago

Actually, you need to modify 2 lines in connection.py. 1) line 111. from data = data.encode('utf-8') to data = data; 2) line 120. from request = Request(url, data, headers) to request = Request(url.encode('utf-8'), data, headers)

hope it works for you.

mariusmuntean commented 8 years ago

@treeguard you were right. Making those two changes did the trick. Thanks!

konoufo commented 8 years ago

Doesn't this need a PR for a clean integration into the library ?

konoufo commented 8 years ago

I suggest passing a keyword argument into the class method POST through File save method when dealing with binaries. Something like no_encoding = True; And then a simple check will bypass encoding only with binaries.

MasterGroosha commented 8 years ago

@konoufo Parse is going to be closed in 6 months. Do we really need this PR now?

konoufo commented 8 years ago

Other Parse Server hostings might support this.

Date: Fri, 8 Jul 2016 23:20:15 -0700 From: notifications@github.com To: ParsePy@noreply.github.com CC: konoufo@hotmail.fr; mention@noreply.github.com Subject: Re: [milesrichardson/ParsePy] Upload File/Images. (#15)

@konoufo Parse is going to be closed in 6 months. Do we really need this PR now?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

MasterGroosha commented 8 years ago

@konoufo Which ones, for example?

konoufo commented 8 years ago

Maybe Sashido or back4app; did not read all the docs but well it's a possibility.

Date: Sat, 9 Jul 2016 01:06:58 -0700 From: notifications@github.com To: ParsePy@noreply.github.com CC: konoufo@hotmail.fr; mention@noreply.github.com Subject: Re: [milesrichardson/ParsePy] Upload File/Images. (#15)

@konoufo Which ones, for example?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

el-mail commented 8 years ago
        connection = http.client.HTTPSConnection('api.parse.com', 443)
        connection.connect()
        connection.request('POST', '/1/files/image.png', open(myImage.png, 'rb').read(), {
               "X-Parse-Application-Id": "",
               "X-Parse-REST-API-Key": "",
               "Content-Type": "image/png"
             })
        result = json.loads(connection.getresponse().read().decode('utf-8'))
        restaurant = Restaurant(name = x.name, image={'__type': 'File', 'name':result['name'], 'url':result['url']})
        restaurant.save()