How do I upload to someone else's ShareFile account?

  • 1
  • Question
  • Updated 2 months ago

Our customer’s hold audio conferences which they may record and request we automatically upload those recordings as MP3 files to their ShareFile.

 

I have written a c# application to access my own ShareFile account via the API using my own username and password to authenticate. The Citrix site documentation has been very useful. I have upload, download, and browsed my own share file account beautifully.

 

What I need is an example of how I would upload to one of my customers Share File accounts. My Customers do not want to give me their user name and password. They will send me a ShareFile file request url.  Then whenever they record a conference I would like to programmatically upload the file to their Share File via the API. How do I authorize such an upload? Can anyone point me to an example of how this is done?
Photo of David Galanti

David Galanti

  • 3 Posts
  • 1 Reply Like

Posted 2 months ago

  • 1
Photo of David Galanti

David Galanti

  • 3 Posts
  • 1 Reply Like
It has been a few days since I posted this. Since I have learned that the ID in a share link matches the ID of the customers shares. I have also learned that if I click a share link and watch the network tab of my debug tool while manually uploading a file they use this syntax.

https://{0}.sf-api.com/sf/v3/Shares({1})/Upload2

How ever a still can't tell if they authenticated, used their API etc... I also cannot get my code too work going to the same place or reading the documentation found here for that call. https://api.sharefile.com/rest/docs/resource.aspx?name=Shares

I get messages like "The remote server returned an error: (405) Method Not Allowed.".

I believe my request is down to simply. The Upload2 method of Shares behaves differently then any of the other methods which seem to work fine for me. Can I get a sample of how to use this method?
(Edited)
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 732 Posts
  • 102 Reply Likes
Hey David,

Sorry for the delay in getting back to you. Your findings are correct, you are supposed to use the Upload2 endpoint using the Id of the share provided to you. 

Regarding authentication, each Share will have different requirements. Some Shares require that the user login, which means that the person providing you the link must also create a username/password on their account for you. Some Shares are anonymous and can be uploaded to without authentication. 

The subdomain you'll use to make the API call is the subdomain of the account you are uploading to, where the link was generated. Following the sample in the documentation website, you should be able to make a request such as:

POST https://account.sf-api.com/sf/v3/Shares(id)/Upload2
{
"Method":"Method",
"Raw": false,
"FileName":"FileName",
"FileLength": 123
}

This will return back an object with a "ChunkUri" url; you can then POST your file to that url using a multi-part format, same way the general upload to a Folder would work.

If you are using the C# SDK for integrating with the API, I'll be happy to provide a sample for this.

Thanks,
Eli

(Edited)
Photo of David Galanti

David Galanti

  • 3 Posts
  • 1 Reply Like
Yes, I have been able to get past most of that already by using c# the "UploadFile" to a parentID example on your website. https://api.sharefile.com/rest/samples/csharp.aspx

I now realize that your upload methods are really requests for upload that return URLs where I must do a second post with the actual file upload.

I am now at the point where everything is working except when uploading to a share the first two lines of every file are skipped. By lines I mean regardless of the length of the line the first two lines up to the carriage returns are missing. In the example below I post this in the upload but even though lines 00 and 01 show in the upload post they are missing from the file when I logon to share file to view it.
--upload-ee7590baf7d54b99a2f93a12f83b9769
Content-Disposition: form-data; name="File1"; filename="uploadTest.txt"\r\nContent-Type: application/octet-stream\r\n\r\n
00 Benny and the Jets
01 
02 Hey kids, shake it loose together
03 The spotlight's hitting something
04 That's been known to change the weather
--upload-ee7590baf7d54b99a2f93a12f83b9769-- 
I am using the c# example UploadMultiPartFile from your site to build this upload which is found at https://api.sharefile.com/rest/samples/csharp.aspx. This function works fine for the "UploadFile" to a parentID example but for some reason the upload to a share expects files that start with two unused lines. 

I can buffer every file with two lines and it works great but I would like to know why I am doing this. Are files uploaded to share expected to have two lines header information? What should I put in those line.

Thanks in advance for your help.
Dave 





Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 731 Posts
  • 102 Reply Likes
Interesting, I've never heard of an issue with the two first lines being removed, the upload process to a folder and to a Share should be identical. I can take a look at this, will get back to you no later than Tuesday next week.

Thank you,
Eli
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 731 Posts
  • 102 Reply Likes
David,

I've written sample code to perform the upload successfully. This sample uses two different upload methods: a "legacy" one based off the sample code on the api site, and the "SDK" one, using our C# ShareFile SDK, the recommended way to interact with the API from a .net application. Both work successfully for me without cutting off the first lines, could you give this a try and see if you have the same experience? The sample also shows how much simpler the code is with our SDK, so I hope it sparks your interest if the .NET version of your project can support it. Let me know if you have any questions.

Code repo: https://github.com/eliezer15/sharefileUploadSample/tree/master/SfUploaderSample

Thanks,
Eli