I'm trying to upload photo via OData.
I've started with this code: https://community.creatio.com/questions/how-upload-attachments-odata
and this is where I'm stuck: picture is uploaded but nothing changes (product photo is still empty), as if nothing is saved...
This is the code that I'm using:
using (var fs = new FileStream("c:/temp/otter_tiny.jpg", FileMode.Open)) { DataServiceRequestArgs args = new DataServiceRequestArgs(); //Define content type args.ContentType = "application/octet-stream"; var productImage = new BPMSync.BpmService.SysImage(); productImage.Id = Guid.NewGuid(); productImage.Name = "produtImage.jpeg"; productImage.MimeType = "image/jpeg"; service.AddToSysImageCollection(productImage); existingProduct.PictureId = productImage.Id; //Save changes DataServiceResponse responces = service.SaveChanges(); //Write file stream to activity file service.SetSaveStream(productImage, "Data", fs, true, args); //Save changes service.SaveChanges(); }
Like
1 comments
09:56 Dec 10, 2019
We figured it out in the meantime, so maybe this will help others:
existingProduct was not actually saved because changing PictureId was not triggering change detection. Manually updating object solved the problem, like this:
service.UpdateObject(existingProduct); service.SaveChanges();
Show all comments