444
Views
7
Comments
Multipart file upload
Question

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?

Attachment_v7.oml
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

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.

UserImage.jpg
Saurav Sircar

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.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

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.

2019-10-27 01-32-56
Caio Santana Magalhães
 
MVP

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.

UserImage.jpg
Meri meri

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"

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

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

2014-10-21 20-15-17
Alberto Ferreira

Hello Meri meri,

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


Best Regards

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.