· Jan 3, 2019

Business Operation to Integrate with Amazon S3 , How to send File to Amazon S3 using HTTP Outbound

Hi All,

I created a Business Operation to Integrate with Amazon S3.
I have used HTTP Outbound Adapter for the same. Used Get method of Adapter Class.
Basically in a request I want to send Unique File Name and File and in Response I want to get Version ID and if operation was successful, then set flag to true.

I have created a class for request in that I have two properties, as shown Below :

    Property fileName As %String;
    Property file As %GlobalBinaryStream;

This is in my Operation Class

            set pResponse = ##Class(SaveFileResponse).%New()
            set fileName = pRequest.fileName
            set file = pRequest.file

            set tSC = ..Adapter.Get(.HttpResponse,"filename",fileName)
            if (HttpResponse.StatusCode = 200) {
                set pResponse.fileSaved = 1
                set pResponse.fileVersionID = HttpResponse.ContentInfo
            else {
                set pResponse.fileSaved = 0

I have also created Business Operation in Production and configured URL and HTTP Configuration and SSL Configuration in Settings for the same.

Is this all correct ? Is my approch okay ?

Kindly help me on this . 

Discussion (8)0
Log in or sign up to continue

Thanks @Eduard Lebedyuk , Actually that my mistake I missed XDATA Mapping.

But I was successfully able to connect to Amazon with Operation and as a Service I was using Enslib.File.PassThrough Service.
But in this approch I will have to store file at a location and fetrch from that for sending to operation.

But I dont want to store files in any filepath rather want to just direct pass a file coming as a request in Service and calling Operation .

I am unable to do that , How can I achieve this ?

Actually I tried to pass the file to Business Service and it is coming up in BS but when I call BO and pass the file as Input, in BO File is Blank. 

@Eduard Lebedyuk  There is one problem , The file gets successfully saved in S3 , but when we try to retrieve the content the data is damaged.

This works fine for text files but if we have any file which is PDF or Image then when we try to view that same file the data is completely damaged we get in the for stream, but not actual image or PDF which we had uploaded.

How can I get the original file(image/PDF) which I uploaded back as a response instead of a stream?

Looks like there's a character stream somewhere. You should always use binary streams to upload binary data such as images, PDFs and so on.

First of all you need to understand where the problem is: on sending or on receiving.

To do that upload PDF using your BO and download it from AWS website manually (using your browser). If you can open downloaded file, then it means that your upload code is correct and the problem is with download code. If you can't open the file it means that you need to check upload code.