UWP c# - Can't use file after being filepicked

I'm trying to upload a file on amazon s3, after filepicked it.

To start, I do this :

       var picker = new Windows.Storage.Pickers.FileOpenPicker();
       picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
       picker.SuggestedStartLocation =
            Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
       picker.FileTypeFilter.Add("*");

       Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

so here, file is picked and ready to be use.

After that, I try to upload it, like that :

        if (file != null)
        {
            upload(file.Path);
        }
       ...

      public async Task<string> upload(string path)
        {
           TransferUtility utility = new TransferUtility(...);
           await utility.UploadAsync(path,key, bucket); // HERE IS THE PROBLEM

        }

and so , this is the error I catched :

Exception thrown: 'System.AggregateException' in mscorlib.ni.dll System.AggregateException: One or more errors occurred. ---> System.UnauthorizedAccessException: Acces denied.

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at PCLStorage.WinRTFileSystem.d__0.MoveNext() --- End of inner exception stack trace --- at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1.get_Result() at Amazon.S3.Transfer.TransferUtility.validate(TransferUtilityUploadRequest request) at Amazon.S3.Transfer.TransferUtility.GetUploadCommand(TransferUtilityUploadRequest request, SemaphoreSlim asyncThrottler) at Amazon.S3.Transfer.TransferUtility.UploadAsync(String filePath, String bucketName, String key, CancellationToken cancellationToken) at Tilkee.Upload.d__0.MoveNext() ---> (Inner Exception #0) System.UnauthorizedAccessException: Acces denied.

I tried to put it in another Task async, but same result.

Any ideas?

Answers


We cannot access files using its path unless the file is in the accessible location like app installation folder, known folders like music lib since UWP apps are isolated and run in sandbox. FileOpenPicker helps in the app to let user choose to broke the app container and access to the files, yes, we can then access this file for example using stream, we can also get the path of this file, but the path here cannot be used to access this file again when you want to upload this file. For more information, you can refer to Skip the path: stick to the StorageFile.

My suggestion is that after the file is picked, access the file stream and try to upload this file stream.


Need Your Help

XPath: Selecting nodes included by an <xsl:include>

xslt xpath

There's an XSL that includes another XSL:

Magento - Customer Login Page Change

php css magento

I am working on magento and new for magento i use lots of templates now i am working on Magento Classic Theme , i google it alot lots of person says changes possible in base default i will go there...