Comments (4)
Check KeeneState's open issue "sample code generates a 400 bad request #117".
from azure-sdk-for-media-services.
I already resolved this issue using similar way.
from azure-sdk-for-media-services.
Great, I am facing problems in the next step. Could you tell me how you solved this, maybe it would help me out.
Thanks in advance!
from azure-sdk-for-media-services.
Sure, here's my working code on production (var names & message changed):
private IAsset CreateMediaAsset(CloudFile model, string lecId)
{
CloudMediaContext context = new CloudMediaContext(mediaAccountName, mediaAccountKey);
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer mediaBlobContainer = cloudBlobClient.GetContainerReference(storageContainerReference);
mediaBlobContainer.CreateIfNotExists();
// Create a new asset.
IAsset asset = context.Assets.Create("Lec-" + lecId + "-" + Guid.NewGuid(), AssetCreationOptions.None);
IAccessPolicy writePolicy = context.AccessPolicies.Create("writePolicy", TimeSpan.FromMinutes(120), AccessPermissions.Write);
ILocator destinationLocator = context.Locators.CreateLocator(LocatorType.Sas, asset, writePolicy);
// Get the asset container URI and copy blobs from mediaContainer to assetContainer
Uri uploadUri = new Uri(destinationLocator.Path);
string assetContainerName = uploadUri.Segments[1];
CloudBlobContainer assetContainer = cloudBlobClient.GetContainerReference(assetContainerName);
string fileName = HttpUtility.UrlDecode(Path.GetFileName(model.BlockBlob.Uri.AbsoluteUri));
var sourceCloudBlob = mediaBlobContainer.GetBlockBlobReference(fileName);
sourceCloudBlob.FetchAttributes();
if (sourceCloudBlob.Properties.Length > 0)
{
IAssetFile assetFile = asset.AssetFiles.Create(fileName);
var destinationBlob = assetContainer.GetBlockBlobReference(fileName);
destinationBlob.DeleteIfExists();
destinationBlob.StartCopyFromBlob(sourceCloudBlob);
destinationBlob.FetchAttributes();
if (sourceCloudBlob.Properties.Length != destinationBlob.Properties.Length)
model.UploadStatusMessage += "Failed to copy as Media Asset!";
}
// Delete destination locator as we want our assets to access through media services only
destinationLocator.Delete();
writePolicy.Delete();
// Delete temp blob to free up chunked uploaded space
sourceCloudBlob.Delete();
// Refresh the new asset
asset = context.Assets.Where(a => a.Id == asset.Id).FirstOrDefault();
var ismAssetFiles = asset.AssetFiles.ToList().Where(f => f.Name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase)).ToArray();
if (ismAssetFiles.Count() != 1)
throw new ArgumentException("The asset should have only one, .ism file");
ismAssetFiles.First().IsPrimary = true;
ismAssetFiles.First().Update();
model.UploadStatusMessage += " File uploaded successfully by id: " + asset.Id;
model.AssetId = asset.Id;
return asset;
}
Hope this helps, let me know if you still face issue.
from azure-sdk-for-media-services.
Related Issues (20)
- AssetFile.Name max length is wrong HOT 1
- AssetFile.Name invalid characters { }
- IAssetFile.Upload(Stream stream) HOT 1
- unsupported audio codec: adpcm_ima_qt, name: ADPCM IMA QuickTime
- .NET Web API HOT 1
- Create new Asset and get Media Processor
- Calling job.SubmitAsync() results in Exception: System.InvalidOperationException: An error occurred while processing this request. ---> System.IO.IOException: Unable to read data from the transport connection: The connection was closed.
- Sometimes get asset id null
- Could not load type 'Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters HOT 2
- Method not found: 'Void Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters..ctor(Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior)'. HOT 7
- release alpha version of preview 3, we want dotnet core support (ARM can wait til beta)
- Uploaded files with BlobTransferClient doesn't show online
- Input .jpg image to azure media service rtmp server possible?
- .NET Standard/Core version HOT 1
- Expiration time of current access token
- could not load Microsoft.Identity.Model.Clients.ActiveDirectory.Plaftform.dll HOT 3
- How to prevent video preloading in mobile browser?
- Not able to update Xamarin.Forms 5.0 in project because of Microsoft.IdentityModel.Clients.ActiveDirectory nugets has dependency in Mono.Android8.1 HOT 1
- This repo is missing a license file
- This repo is missing important files HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-sdk-for-media-services.