cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We love to hear how every person gets the most from Dropbox, and it seems everyone has a slightly different use for it - tell us yours here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting "Stream does not support seeking" with GetContentAsStreamAsync

Getting "Stream does not support seeking" with GetContentAsStreamAsync

donaldp
Collaborator | Level 8

Hi,

   I'm currently using a C#/.NET nuget which works as expected when printing from an embedded resource as a stream. The problem is that it's not working when I try to use a Dropbox stream instead - I get "Stream does not support seeking".

So, this code works....

Stream fileStream=typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("MyAppName.Assets.111Z50066336EXP00065.pdf");

This doesn't...

string fileToPrint=RootFolder+"Labels/A10835/111Z50066336EXP00065.pdf"; //this is just the same file in a different location obviously
Stream fileStream=await DataService.StreamFile(fileToPrint);

Where DataService is my Dropbox class, RootFolder is my Dropbox root folder, and StreamFile is as follows...

public async Task<Stream> StreamFile(string file)
{
    try {
        using (DropboxClient DxClient=new 
        DropboxClient(AccessToken)){
            var response=await DxClient.Files.DownloadAsync(file);
            var content=response?.GetContentAsStreamAsync();
            return content?.Result;
        }
    }
}

 

So how do I need to alter this code to not get this "does not support seeking" message? i.e. why is my Dropbox stream not beaving the same as streaming the embedded resource, and how do I get it the same?

 

thanks,

  Donald.

1 Accepted Solution

Accepted Solutions

Re: Getting "Stream does not support seeking" with GetContentAsStreamAsync

donaldp
Collaborator | Level 8

Well, I got it working! But not with native Dropbox API command, so I'm still itnerested if there's a way to do it with the API.

Courtesy of this SO post https://stackoverflow.com/questions/23626965/this-stream-does-not-support-seek-operations-using-stre... I got it working with this code...

string fileToPrint=RootFolder+"Labels/A10697/111Z50066345EXP00001.pdf";
Stream fileStream=await DataService.StreamFile(fileToPrint);
MemoryStream ms=new MemoryStream();
fileStream.CopyTo(ms);
// then use ms in place of fileStream

If there's a way to get around this with Dropbox API, then let me know and I can try it that way and mark your reply as answer, but if not we can mark this as answer.

View solution in original post

3 Replies 3

Re: Getting "Stream does not support seeking" with GetContentAsStreamAsync

donaldp
Collaborator | Level 8

Well, I got it working! But not with native Dropbox API command, so I'm still itnerested if there's a way to do it with the API.

Courtesy of this SO post https://stackoverflow.com/questions/23626965/this-stream-does-not-support-seek-operations-using-stre... I got it working with this code...

string fileToPrint=RootFolder+"Labels/A10697/111Z50066345EXP00001.pdf";
Stream fileStream=await DataService.StreamFile(fileToPrint);
MemoryStream ms=new MemoryStream();
fileStream.CopyTo(ms);
// then use ms in place of fileStream

If there's a way to get around this with Dropbox API, then let me know and I can try it that way and mark your reply as answer, but if not we can mark this as answer.

View solution in original post

Re: Getting "Stream does not support seeking" with GetContentAsStreamAsync

Greg-DB
Dropboxer

I'm glad to hear you already sorted this out, and thanks for sharing your solution!

I don't believe the streams returned for downloads in the Dropbox .NET SDK natively support seeking, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though. 

Based on the error, it sounds like whatever you're using the stream with attempts to do some Seeking.

The main difference here appears to be that the stream from your GetManifestResourceStream call is getting a local resource, whereas the stream from the Dropbox API DownloadAsync call is getting a remote resource over the network. From Microsoft's Stream documentation:

network streams have no unified concept of a current position, and therefore typically do not support seeking.

Your workaround appears to work by reading the data off the network stream first and copying it to a memory stream.

Re: Getting "Stream does not support seeking" with GetContentAsStreamAsync

donaldp
Collaborator | Level 8

Ah ok, that makes sense. Thanks for explaining Greg!

Who's talking

Top contributors to this post

  • User avatar
    donaldp Collaborator | Level 8
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?