Multipart file upload

Multipart file upload

  

Hi. I'm currently trying to use the pending_attachment API provided by Yammer (Endpoint: https://www.yammer.com/api/v1/pending_attachments).

I contacted Yammer support, and this is the code they provided me with in C#:

public static async Task<PendingAttachment> Upload(string FilePath)
    {
        byte[] byteFile = System.IO.File.ReadAllBytes(FilePath);
        FileInfo fi = new FileInfo(FilePath);
 
        PendingAttachment pa = null;
        using (var client = new HttpClient())
        {
            string token = "XXXXXXXXXXXXX";
            client.DefaultRequestHeaders.Add("Authorization", "Bearer" + token);
            using (var content = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture)))
            {
                content.Add(new StreamContent(new MemoryStream(byteFile)), "attachment", fi.Name);
 
                using (var message = await client.PostAsync("https://www.yammer.com/api/v1/pending_attachments", content))
                {
                    if (message.IsSuccessStatusCode)
                    {
                        var result = await message.Content.ReadAsStringAsync();
                        pa = Newtonsoft.Json.JsonConvert.DeserializeObject<PendingAttachment>(result);
                        return pa;
                    }
                }
            }
        }
        return null;
    }
 
    var FilePath = @"<FILE PATH>";
    var pa = await Upload(FilePath);
 
    MessageParam message = new MessageParam()
    {
            body = "posting attachment",
            group_id = XXXXXXX,
            pending_attachment1 = pa.id
    };
    var result = await CreateMessageAsync(message);

I tried doing this on Outsystems but to no avail. I referenced the Box File upload.

Here's the OML file: 

Attachment.oml

Can someone please help me out?

Hi Saurav,

The code Yammer provided is C#. In order to use that, you need to create an Extension. You can't integrate C# code in an eSpace.

Kilian Hekhuis wrote:

Hi Saurav,

The code Yammer provided is C#. In order to use that, you need to create an Extension. You can't integrate C# code in an eSpace.

I know its C#. I wanted to know if an equivalent request call can be made using the REST feature on Outsystems.

Right, sorry for the misunderstanding. There seem to be two things going on: the first is adding an authorization header, and the second adding an attachment. As for the first, you can use the OnBeforeRequest for that. As for the second, perhaps the information from this topic can help you.

Hello,


For those who may be still facing this issue: I've published a Forge component which helps submitting multipart/form-data content.

https://www.outsystems.com/forge/component/3731/multipart-upload/


Thanks.

For anyone who comes across this topic, here's an Idea to have OutSystems support it natively. Please like :).

Caio Santana Magalhães wrote:

Hello,


For those who may be still facing this issue: I've published a Forge component which helps submitting multipart/form-data content.

https://www.outsystems.com/forge/component/3731/multipart-upload/


Thanks.

Hell,

I have tried this
but always error.

the error is " the connection has timed out"

Hello Meri meri,

the best place to post your contribution will be in the Forge component support forum


Best Regards