Attachment Download Issues?

From the API, I can pull the attachment info (including url). If I want store and later access that file (i.e. download it) later from a different app, what is the process? I won't be in a authenticated session, but have the link. Any suggestions?

Or, just any programmatic way to download attachment even calling the API directly (via authenticated request).

Comments

  • Michael Reece
    Michael Reece Blackbaud Employee
    Eighth Anniversary Name Dropper Facilitator 1 Blackbaud Staff

    @Bob Rowe, the URL that comes back in the response has all the authentication you need burned into the querystring on the URL. The access supplied in the URL is only good for one hour for security reasons. If you look closely at the URL you can see the Expiration datetime.

    Here is some example code of how you could download an Attachment with the supplied URL and FileName using c#.

    var fileURL = "https://url_supplied_from_original_response";
    var localFile = @c:\\folder_for_files\\filename_from_original_response;
    using (var client = new HttpClient())
    {
    using (HttpResponseMessage response = await client.GetAsync(fileURL))
    using (Stream streamToReadFrom = await response.Content.ReadAsStreamAsync())
    using (var fs = new FileStream(localFile, FileMode.Create, FileAccess.Write, FileShare.None))
    {
    await streamToReadFrom.CopyToAsync(fs);
    }
    }

    Let me know if this helps of if you have any further questions.

  • Bob Rowe
    Bob Rowe New Member
    Second Anniversary Kudos 1 Name Dropper Participant

    @Michael Reece Thanks - that did the trick! I hadn't inspected the URL parameters in detail.

Categories