question

Upvotes
Accepted
68 3 4 8

Extracting a full file

Hello everybody,

I am trying to download the files after an asynchronous extraction.

From the web interface, the file is downloaded properly and can be opened with 7zip.

With the code, I do something like this with each f in CompletedExtraction.Files :

    var streamResponse = extractionsContext.ExtractedFileOperations.GetReadStream(f);
    string strFileName = f.ExtractedFileName;
    string contents = string.Empty;
    using (var reader = new StreamReader(streamResponse.Stream))
    {
        contents = reader.ReadToEnd();
    }
    using (System.IO.StreamWriter outputfile = new StreamWriter(@"C:\dev\target\" + strFileName))
    {
        outputfile.Write(contents);
    }

and it appears that 7zip cannot open the file, as it is not an archive. It is not readable by a human either, that being said. There is no problem with the notes file, that is quite readable after being imported that way, only the full file, of type gz, cannot be opened.

Anything I missed ?

tick-history-rest-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
13.7k 26 8 12

@Hubert CANEVET, can you try this:

var streamResponse = extractionsContext.ExtractedFileOperations.GetReadStream(f);
string strFileName = f.ExtractedFileName;
{
    using (FileStream fileStream = File.Create(@"C:\dev\target\" + strFileName))
        streamResponse.Stream.CopyToAsync(fileStream).Wait();
}

Caveat: I tested this code in a different context, but I believe it should work.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
68 3 4 8

OK nice, it works !

Thank you.

That deserves to be documented somewhere. In the example application I looked at ExtractNow, FetchAllFiles, Extracted Files : Get Latest, and perhaps some other places.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Glad your issue is solved !

That code comes from my .Net SDK tutorial 2, but it is not obvious to look in there as the use case is different (a VBD download).

Click below to post an Idea Post Idea