Determine attachment filename / filetype using HTTP REQUEST Activity

Hi

I m trying to download attachment from a API call using HTTPS REQUEST activity
I m aware that I can pass the Filename I want that gets downloaded as the attachment
But if the api can have any type of attachment in it like .eml or xlsx file, How can I mention the Filename and filetype of the attachment without knowing what it would be from api
When I tried the same with postman (with Save and Download option) I m able to download the file with its actual name and filetype
But in studio I couldn’t

Or

Is there any way to get any type of attachments from api with its actual file name and file type

Cheers

1 Like

A list of different options which can be used or combined:

  • URL Analysis
  • Response Header - Content-Type
  • Sending a Previous Call using HTTP Method: HEAD
  • Using a newer version of Http Request - and retrieving the FileName from the ILocalRessource

Can check a few options more / sometimes we can better catch info with a custom HttpClient implementation of the Call

Can u guide me with this @ppr

suggestion would be to start with HTTP/Header/Content-Disposition / Location catching

when this is fine for you. Do you have any url to run the demo against?

1 Like

Yeah
I use a coupe api url
Where I’m passing url to get the attachment like this

{url}\api\attachments{attachment id}

  1. Where I m getting the attachment id from another url

  2. With the above url I get Json response but it is of junk characters. I think it is trying to parse through the attachment and give as output response and it doesn’t have any Filename or filetype

  3. With the url I use to get attachment id also doesn’t give any other details of the attachment

@ppr

Hi @Palaniyappan

Content-Disposition will be a good option to find the file name.

I have tried a sample, in this content disposition is not available so used content type.

Http_DownloadUnknownFile.zip (2.9 KB)

Hope this helps.

Thanks
#nK

1 Like

@Palaniyappan
Can you please check the following (we would like to check for a flat solution approach)

Compatibility: Windows
grafik
yellow Mark - set your URL

grafik
myResponse =

myHTTPClient.SendAsync(new HttpRequestMessage(HttpMethod.Head, strURL))

then check in immediate panel:
grafik
is it showing the full URI with filename and extension?

Kindly note:

  • with the HEAD Request we ask for meta and are not doing the download
  • we do feel that we will enhance it
2 Likes

May I know what datatype u r referring for this variables

myHTTPClient
myresponse

@ppr

1 Like

grafik

System.Net.Http
System.Net.Http.HttpResponseMessage

1 Like

I couldn’t find that type even though I have system.net imported @ppr

Are you running on legacy?

Yeah
Even I don’t have an option to change the project type
It’s 2020.10.6 version
Little old
@ppr

@Nithinkrishna
Can u pls forward me this with mail
I couldn’t open for some reason

when working with Legacy we would reference the following:

1 Like

we did run some side-by-side checks along with different scenarios and cross-checking in Postman.

For a more reliable solution, we would recommend to set up a cascade:

  • check if Content-Disposition Header is available
  • check if the request URL can be used
  • Check if the above shown Result.RequestMessage.RequestUri give details
  • Check Response.Location

It can happen, that a file name / info still cannot be determined. Then derivation from content-type or a default name can be used as alternate / fallback

Kindly note: not every content-type allows a clear derivation of the filetype / type extension

1 Like

Great
Thanks @ppr
Appreciate ur kind help
I got it resolved with Nithin’s suggestion by getting Content Deposition where it had the Filename and filetype which I used for saving my file from api
Thanks @Nithinkrishna

Content Deposition OR content type

We keep in mind that Content Deposition is an optional header

Within the implementation we had seen:

Can you please clear what was finally used?

For a check call you could use e.g
https://go.microsoft.com/fwlink/?LinkID=521962

1 Like

U r right
It’s Content-Type which has the Filename and type
@ppr

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.