Skip to content

Latest commit

 

History

History
33 lines (19 loc) · 3.08 KB

File metadata and controls

33 lines (19 loc) · 3.08 KB

Web API File Operations with chunks sample

This document describes the how the FileOperationsWithChunks project implements the common operations described in Web API File Operations sample. See that document for an overview and how to run this sample.

Demonstrates

The FileOperationsWithChunks project demonstrates how to work with files using standard Http methods and the Dataverse Web API.

This sample uses classes defined within the WebAPIService project Messages folder so that they can be re-used. These classes inherit from the .NET HttpRequestMessage and HttpResponseMessage classes. These classes have constructors that accept the relevant variables to compose the requests to send, or to deserialize the responses into standard properties.

The code for this sample is in the Program.cs file.

Upload File

To upload a PDF file named 25MB.pdf to the sample_FileColumn file column on the account record, this sample uses an UploadFile static method that accepts all the parameters needed to make the following requests:

  1. Initialize the upload with the InitializeChunkedFileUploadRequest class
  2. Process the response with the InitializeChunkedFileUploadResponse class to get the URL from the Location header to send subsequent requests.
  3. Split the file up into 4MB block and send each block using the UploadFileChunkRequest class. This request doesn't have any response value to process.

Download File

To download the PDF file named 25MB.pdf that was just uploaded to the sample_FileColumn file column on the account record, this sample uses an DownloadFile static method that accepts all the parameters needed to make the following requests:

  1. If the file was succesfully uploaded, instantiate a byte[] variable to capture the contents of the file.
  2. Send a series of DownloadFileChunkRequest class while there are chunks remaining to download.
  3. Process each response with the DownloadFileChunkResponse class to get byte[] data passed in the content of the response. This response also extracts the size of the file from the x-ms-file-size so the total number of iterations required can be known. Copy the data from each response into the byte[] variable.
  4. After all the blocks are recieved, return the byte[] variable.

Delete File

If the file was succesfully uploaded, use the DeleteColumnValueRequest class to delete the file.This method can be used to delete the value of any type of column. This request doesn't have any response value to process.