Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Here's some sample code that I've used in the past:
HttpPostedFileBase uploadedFile = Request.Files[i];
if (uploadedFile == null || uploadedFile.ContentLength == 0)
{
continue;
}
var genericMedia = this._contentRepository.GetDefault(rootFolderContentReference);
genericMedia.Name = uploadedFile.FileName;
var blob = this._blobFactory.CreateBlob(genericMedia.BinaryDataContainer, Path.GetExtension(genericMedia.Name));
blob.Write(uploadedFile.InputStream);
genericMedia.BinaryData = blob;
this._contentRepository.Save(genericMedia, SaveAction.Publish, AccessLevel.NoAccess);
Hope it helps.
Frederik
Hi.
I'm trying to store an image with the BlobFactory, but I'm obviously doing something wrong. The image gets stored, but when I try to download it. The image viewer on my machine says it either too large or corrupted. It's probably corrupted, because before I upload the picture I can view it in the image viewer.
This is my code:
I've been following this post. In this example he only stores text to a .txt file, which is not what I need.
I've tried to use a StreamReader and .ReadToEnd and that returns a string. I've also tried the BinaryReader (as shown in the code above), but no luck there either.
Does anyone know how to store images properly?
// Anders