November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Hi Patrik
I noticed that you are not resetting the MemoryStream.Position
to 0 in your code sample.
Try adding memoryStream.Position = 0
, just before the content.Add
line.
Holy Badowly, it actually works! Thanks Stefan, you saved my day.
Here is a working code snippet for sending images to Episerver thorugh the Service API without access to disk/file on sending side:
using (var memoryStream = new MemoryStream())
{
using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
{
var demoFile = archive.CreateEntry("MediaImport.xml");
using (var entryStream = demoFile.Open())
using (var streamWriter = new StreamWriter(entryStream))
{
streamWriter.Write("<MediaImport><ContentFolderUri>default content folder uri</ContentFolderUri><MediaType name=\"Image\"><ContentType>Company.Site.Areas.Shared.Media.Image, Company.Site</ContentType></MediaType><MediaGroup mediaTypeName=\"Image\"><Media><IntegrationId>TEST_IMAGE</IntegrationId><Name>Test Media with Binary Content in external URL</Name><BlobContent><ExternalUri>https://static.starcraft2.com/dist/images/global/logos/img-sc2-logo--large.png</ExternalUri></BlobContent></Media></MediaGroup></MediaImport>");
}
}
memoryStream.Position = 0;
content.Add(new StreamContent(memoryStream), "file", "MediaImportHttp.zip");
return PostImport("/episerverapi/commerce/import/assets", content, out taskId);
}
// Patrik
Hi!
I am trying to send an image to Episerver through the Service API (/episerverapi/commerce/import/assets).
The way shown below from the example here https://github.com/episerver/ServiceApi-Client/blob/master/EPiServer.ServiceApi.Client/Tests/Catalog/ImportTest.cs works.
However, my code that initiates the POST to episerver is running in a cloud environment where I do not have access to disk/filesystem. Thus I will need to do this without using an ordinary FileStream. I have tried to do it with a memorystream instead (see below code) but no image is added in Episerver.
(note: It works in a test setup if I convert the memorystream to a filestream and then send it, so the content of the memorystream seems to be correct)
When DotPeeking what the service API does on the recieving side I see this:
Is there some way I can send images to Episerver through the service API without using a actual file/filestream on the sender side?
Thanks
// Patrik