HTTP service request: cannot access request Body -> upload file through HTTP Service

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Active user
Rating: 4
Joined: Feb 9, 2016
Company: CTC

Hi,
I have http service and I'm trying to upload a file from another application and stream it to my http service so that I store in a ValueStorage field. I struggled a lot to find an example for the full scenario. I'm trying to take it step by step now. So first step, If I'm using a http post request and attaching the file in the content, how can I access the content body of an HTTP service?
What I have now is only Method(Requst) and the Requst includes only headers, it does not include body.

Thanking your help. if you can provide help for this specific step then it is great. If you can give me full example for the full scenario of getting the attached file from the request and storing it in a document ValueStorage field then it is GREAT :)

Thanking you

 
#2
People who like this:1Yes/0No
Interested
Rating: 32
Joined: Oct 27, 2011
Company: Abaco Soluciones S.A.

Try smth like this

Code
Connection = New HTTPConnection("server.com",,,,,,New OpenSSLSecureConnection());
   RequestHeaders = New Map();
   RequestHeaders.Insert("Content-Type", "application/json");
   Request = New HTTPRequest("path/a/b", RequestHeaders);
   HTTPResponse = Connection.Get(Request);
   ResponseText = HTTPResponse.GetBodyAsString();

 
#3
People who like this:0Yes/0No
Active user
Rating: 4
Joined: Feb 9, 2016
Company: CTC

Hi Alexey,

thank you for the attempt. the request is coming from outside 1c, from another application. The request hits the post method in my 1C and calls my Handler function. the handler function in 1c is like this
Function HandleRestCAll(Request)
...// need to get request body,
...//need to get attachment from the body
...//need to store attachment in ValueStorage
EndFunction

 
#4
People who like this:0Yes/0No
Active user
Rating: 4
Joined: Feb 9, 2016
Company: CTC

I found a way to get the body from the request using the following method:

BinaryDataBody = Request.GetBodyAsBinaryData();

so this is the first step. now how to get my attached file from it. The request has a multpart.

 
#5
People who like this:0Yes/0No
Active user
Rating: 7
Joined: Nov 3, 2011
Company: 1C Company

Mubarak Sami,

please check the following article: Development of tools for working with binary data, section "Example of reading and writing a multipart HTTP message."

 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.