File download problem with kentico 10 api

somen ghosh asked on December 16, 2016 13:18

I have a file url like "http://localhost:49821/getmedia/8de48361-f3f3-4c9b-a4d4-140bf5d438cb/img1".but when I write the code to download through api-

byte[] fileBytes = System.IO.File.ReadAllBytes(path);

I got the error: "An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code Additional information: URI formats are not supported."

Please help me to solve the issues.

Recent Answers


Suneel Jhangiani answered on December 16, 2016 13:43

The error message is quite clear in that you are using a URI to try and read the local file. Instead you need to get the location of the actual file. I am not sure which method you would use since the URL you posted indicates that it is coming from a Media Library.

0 votesVote for this answer Mark as a Correct answer

somen ghosh answered on December 16, 2016 14:08

Thanks Suneel for your reply.this is my code from where i got the url from medialibrary

List

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on December 16, 2016 17:47

Just get the bytes using the mediafileinfoprovider:

mfi = MediaFileInfoProvider.GetMediaFileInfo(mediafileGuid, CurrentSiteName);
            var bytes = mfi.FileBinary;
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.