Upload a file starting from a IO Stream

  • 1
  • Question
  • Updated 6 months ago
trying to upload a file to ShareFile but I'm coming from a complex external system that has all the files loaded.
the API of said system gives access to the file Stream (IO.Stream in .NET) and apparently not to the full server path of the file.

I guess I have two options, either write the stream to a file (could lead me to have permission issues in the server's folders) or start an upload using the Sharefile API directly with the stream and the filename.

If the second option is viable please point to the methods within the API (or the conversations in the forum) for accomplishing the task.
Photo of Natan Avrahami

Natan Avrahami

  • 4 Posts
  • 0 Reply Likes

Posted 6 months ago

  • 1
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 695 Posts
  • 98 Reply Likes
Natan,

If you are using the ShareFile .NET SDK, there is a method that lets you upload a file from a stream. Here's a sample:

//Assume 'sfClient' is an authenticated ShareFileClient instance, 'stream' is your file Stream, and 'parentFolderUrl' is the Uri of the parent folder
var uploadSpec = new UploadSpecificationRequest
{
  FileName = "filename",
  FileSize = 100 // whatever size the file has
  Parent = parentFolderUrl,
}
var uploader = sfClient.GetAsyncFileUploader(uploadSpec, stream);
await uploader.uploadAsync();
Let me know if that works for you

Best,
Eli
Photo of Natan Avrahami

Natan Avrahami

  • 4 Posts
  • 0 Reply Likes
I'm basing my code on the Sample code available on the website so not sure what sfClient is, I'm using HTTP requests.
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 695 Posts
  • 98 Reply Likes
It comes from using the .NET SDK https://github.com/citrix/ShareFile-NET which we strongly recommend for .NET projects.
If the SDK is not compatible with your project, I'm sure there are other ways to convert a .net stream to a multi-part file for POSTing via Http

Thanks!
Eli