Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateFromBlob crashing #40

Closed
FFRainman opened this issue May 10, 2017 · 3 comments
Closed

CreateFromBlob crashing #40

FFRainman opened this issue May 10, 2017 · 3 comments

Comments

@FFRainman
Copy link

When loading a blob from an Uri and passing it into CreateFromBlob it crashes with the following (weird) error:

System.Data.Services.Client.DataServiceClientException
<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code /><m:message xml:lang="en-US">AssetFile ContentFileSize must not be negative</m:message></m:error>

Example code:

MediaServicesCredentials _cachedCredentials = new MediaServicesCredentials(_mediaServicesAccountName, _mediaServicesAccountKey);

CloudMediaContext _context = new CloudMediaContext(_cachedCredentials);
            
CloudBlockBlob cloudBlockBlob = new CloudBlockBlob(new Uri(model.BlobUri));                

// This row crashes
IAsset inputAsset = _context.Assets.CreateFromBlob(cloudBlockBlob, storageAccount.Credentials, AssetCreationOptions.None);

If I take the same CloudBlockBlob and use a MemoryStream to create it, it works, example:

var assetName = Path.GetFileNameWithoutExtension(cloudBlockBlob.Name);

IAsset inputAsset = _context.Assets.Create(assetName, AssetCreationOptions.None);

var assetFile = inputAsset.AssetFiles.Create(cloudBlockBlob.Name);

using (var memoryStream = new MemoryStream())
{
        cloudBlockBlob.DownloadToStream(memoryStream);
        memoryStream.Position = 0;
        assetFile.Upload(memoryStream);
}
@mconverti
Copy link
Collaborator

@FFRainman The CreateFromBlob extension tries to set the IAssetFile.ContentFileSize and IAssetFile.MimeType properties after successfully creating the asset based on the CloudBlockBlob.Properties of your source blob instance (see AssetBaseCollectionExtensions.cs#L522).

The problem is that CloudBlockBlob.Properties was not loaded after creating your source blob instance. Could you please try adding the following line of code before calling the CreateFromBlob extension?

cloudBlockBlob.FetchAttributes();

Hope it helps!
Mariano Converti
http://southworks.com/blog/author/mconverti/

@FFRainman
Copy link
Author

@mconverti Perfect, that solves my problem!

Hopefully this piece of information can help others as well. :)

@skymanaditya1
Copy link

@mconverti I spent 2 hours trying to debug this on my own. I was using the CopyFromFile function and had to recently change it to CopyFromBlob but it was crashing with the exception similar to the one commented by @FFRainman . Hope this solution reaches its targeted audience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants