ONTAP Rest API Discussions

Copying Files using Rest API

RubyWren
1,195 Views

I would like to read or download files from a volume using the ONTAP Rest API. The “storage/file/copy” is not appropriate as the destination is a container. I can read the files using “storage/volumes/{volume.uuid}/files/{path}…” however the output contains unwanted content. In an example file that contains two lines: “This is a test file.” and Lorem… The result is:

--b62dcee24b2e7920
Content-Disposition: form-data; name="bytes_read"
Content-Type: text/plain

469
--b62dcee24b2e7920
Content-Disposition: form-data; filename="NewTest.txt"
Content-Type: application/octet-stream

This is a test file.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

--b62dcee24b2e7920--

 Is there a way to make an exact copy of files using the API?

2 REPLIES 2

RubyWren
1,110 Views

I see the note: The contents of the file will be stored in the variable "response_files" in the return object. The output does not look like Json that can be parsed for response_files. Is this what the note is stating?

file-read-file

GET /api/storage/volumes/{volume.uuid}/files/{path}

Note: You MUST include \{ "Accept" : "multipart/form-data" \} in the header. The contents of the file will be stored in the variable "response_files" in the return object.

 

RubyWren
998 Views
This is how I extracted the file from the multipart/form-data Using .Net Microsoft.AspNetCore.WebUtilities package: Use the collection of HttpResponseMessage Headers ContentType Parameters to find the name value pair with a name of "boundary". Use the header boundary value in the MultipartReader and read each section of the response. If the section MediaType is "text/plain" and Name is "bytes_read", read the number of bytes from the body. If the section MediaType is "application/octet-stream", stream the body. section.Body.CopyToAsync(…);
Public