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 . 

  • 0
  • 0
  • 139
  • 8
  • 0

Comments

Also , How can I create a Business Service which can call this Business operation from Code Itself.  How can I do this ?

Click "Visual Trace" link to view details.

In your case there's 403 error, so you're not authenticated.

Check this topic for AWS authorization options.

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. 

Use %Stream.GlobalBinary to pass streams without saving them on disk. Also use Ens.StreamContainer as an interoperability message class.

If you used %Stream.TmpBinary class to hold your stream, it would not be saved.

Thanks @ Eduard Lebedyuk , It worked I guess, the way I wanted.
Thank You so much, I just changed the Property of Request class from %BinaryStream to %Stream.Global Binary as You advised.

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