Object reference not set to an instance of an object.
回答済みHi, I'm experiencing the issue that uploading Pdf to the box by API by C#.
While uploading I am getting an unexpected error that Object reference not set to an instance of an object.
I Want just to upload a Pdf and get a Sharable Link with download and view.
Thank you very much.
----------------------------------------
Here is My Code
var config = new BoxConfigBuilder(<Client_Id>, <Client_Secret>, new Uri("https://developer.box.com/auth/callback")).Build();
var client = new BoxClient(config);
BoxFile newFile;
using (FileStream stream = new FileStream(@"C:\\Users\\Dhanraj Kumar\\Desktop\\Test.pdf", FileMode.Open))
{
BoxFileRequest req = new BoxFileRequest()
{
Name = "Test.pdf",
Parent = new BoxRequestEntity() { Id = "0" }
};
newFile = await client.FilesManager.UploadAsync(req, stream);
String Url = newFile.SharedLink.DownloadUrl;
}
-
Hi Dhanraj
If you are trying to get the download URL from a shared link you need to create the shared link first. It is not created automatically when you upload a file.
See: https://github.com/box/box-windows-sdk-v2/blob/main/docs/files.md#create-a-shared-link - this will create a permanent shared link and a download URL as well
You can also use this to get the download URL as well https://github.com/box/box-windows-sdk-v2/blob/main/docs/files.md#get-a-files-download-url but this URL expires after approximately 15 minutes. See https://developer.box.com/guides/downloads/get-url/
So which you use depends on how you are using the download link further in your app
Best regards, Peter Christensen, Platform Solutions Engineer, Box
投稿コメントは受け付けていません。
コメント
1件のコメント