librelist archives

« back to archive

Problem with file binary data

Problem with file binary data

From:
Bruno Garcia
Date:
2013-07-27 @ 01:43
Hello,

I'm using an API in OAuth (I'm using Flask-OAuth) and I have a method to
upload files (images) that I want to use.

The way I want to do it is to have a form in an HTML template, that form
posts the image to my route and that uploads the file through the API
Method.

But the API method requires the file to be sent as binary data.
I tried sending the stream data from the request:

request.files['image].stream.readlines()
>

But that didn't work for me.

What method should I be using to send the binary data through a POST?

Any help is appreciated,
Bruno

Re: [flask] Problem with file binary data

From:
Mauricio de Abreu Antunes
Date:
2013-07-27 @ 02:10
Why did it not work for you?
Do you have any stacktrace or error message?

2013/7/26 Bruno Garcia <garcia.bruno0@gmail.com>:
> Hello,
>
> I'm using an API in OAuth (I'm using Flask-OAuth) and I have a method to
> upload files (images) that I want to use.
>
> The way I want to do it is to have a form in an HTML template, that form
> posts the image to my route and that uploads the file through the API
> Method.
>
> But the API method requires the file to be sent as binary data.
> I tried sending the stream data from the request:
>
>> request.files['image].stream.readlines()
>
>
> But that didn't work for me.
>
> What method should I be using to send the binary data through a POST?
>
> Any help is appreciated,
> Bruno



-- 
Mauricio de Abreu Antunes
Mobile: (51)930-74-525
Skype: mauricio.abreua

Re: [flask] Problem with file binary data

From:
Bruno Garcia
Date:
2013-07-27 @ 04:01
Here's the trace error:


TypeError: You are required to pass either a unicode object or a utf-8
> string here. You passed a Python string object which contained non-utf-8:
> <lots of bytes here>
>

And here's my code using Flask-OAuth post function

oauth.post('attachment/upload', data={'image':
> request.files['image].stream.readlines()})
>



On Fri, Jul 26, 2013 at 11:10 PM, Mauricio de Abreu Antunes <
mauricio.abreua@gmail.com> wrote:

> Why did it not work for you?
> Do you have any stacktrace or error message?
>
> 2013/7/26 Bruno Garcia <garcia.bruno0@gmail.com>:
> > Hello,
> >
> > I'm using an API in OAuth (I'm using Flask-OAuth) and I have a method to
> > upload files (images) that I want to use.
> >
> > The way I want to do it is to have a form in an HTML template, that form
> > posts the image to my route and that uploads the file through the API
> > Method.
> >
> > But the API method requires the file to be sent as binary data.
> > I tried sending the stream data from the request:
> >
> >> request.files['image].stream.readlines()
> >
> >
> > But that didn't work for me.
> >
> > What method should I be using to send the binary data through a POST?
> >
> > Any help is appreciated,
> > Bruno
>
>
>
> --
> Mauricio de Abreu Antunes
> Mobile: (51)930-74-525
> Skype: mauricio.abreua
>