0

I have successfully been able to upload a file Sample.pdf using a C# program utilizing the Box API. (client_id, client_secret, code, POSTMAN, etc)

 BoxApi.V2.Authentication.OAuth2.OAuthToken newToken = default(BoxApi.V2.Authentication.OAuth2.OAuthToken);

        clientID = "blah blah";
        clientSecret = "blah blah";

        TokenProvider tokenProvider = new TokenProvider(clientID, clientSecret);

        StreamReader streamReader = default(StreamReader);
        streamReader = System.IO.File.OpenText(@"C:\BoxApiRefreshToken.txt");
        oldRefreshToken = streamReader.ReadToEnd();
        streamReader.Close();

        newToken = tokenProvider.RefreshAccessToken(oldRefreshToken);
        BoxManager boxManager = new BoxManager(newToken.AccessToken);

        StreamWriter streamWriter = new StreamWriter(@"C:\BoxApiRefreshToken.txt");
        streamWriter.Write(newToken.RefreshToken);
        streamWriter.Close();

        Folder rootFolder = default(Folder);

        rootFolder = boxManager.GetFolder(Folder.Root);

        BoxApi.V2.Model.File file = boxManager.CreateFile(rootFolder, attachedFilename, ConvertStreamToByteArray(stream));

Once uploaded, I was just wondering how can I retrieve the public URL to access this file in C# program? I assumed sharedlink is a way but I am not sure how.

Thanks

blue piranha
  • 3,706
  • 13
  • 57
  • 98

1 Answers1

0

make a PUT call on the same file-id that you just got back from your upload. Set the Shared-link section of the JSON with the shared-link permissions that you want. Assuming you have privileges to create the shared-link, it will come back in the response to your PUT request.

Peter
  • 2,551
  • 1
  • 14
  • 20
  • Peter, can you please provide a small piece of code? Much appreciated. – blue piranha Oct 01 '14 at 14:44
  • var fileId = boxManager.GetFile(file.Id); var sharedLink = new SharedLink() { Permissions = new Permissions() { CanDownload = true, CanPreview = true } }; boxManager.ShareLink(fileId, sharedLink); Console.WriteLine("Shared Link is " + sharedLink.DownloadUrl); The downloadurl is null – blue piranha Oct 01 '14 at 15:04