C
C#16mo ago
linqisnice

❔ How to best upload images to an entity that doesn't yet exist

Not sure if the title makes sense. When you create an accomodation, you can also upload images. But uploading images to blob storage is a different endpoint and it takes in the id of the accomodation... which doesn't yet exist. All the solutions I've come up with seem long-winded and overly complex.
8 Replies
linqisnice
linqisnice16mo ago
Basically, the problem is, you need an identifier to associate with the uploaded file but that identifier doesn't exist yet since the db record isn't yet created
Preda
Preda16mo ago
partial class?
linqisnice
linqisnice16mo ago
@Predanot sure it solves the problem. The problem is that I dont want accomodations created without a photo. It's easy to disjoint the process of creating an accomodation and uploading images, but i'm not sure a partial class will allow me to require photo uploads during hte creation of an accomodation
Preda
Preda16mo ago
You can always try
linqisnice
linqisnice16mo ago
@Preda Whayt about just queueing the endpoint calls on the frontend? or a conditional trigger trigger first endpoint 1 to create listing and if it succeeds and returns id uploda photo
Preda
Preda16mo ago
You didn t mention anything about a website
Angius
Angius16mo ago
Don't make it a separate endpoint, handle it all in the same one
var thing = new Thing {
Name = data.Name,
Count = data.Count,
Date = DateTime.Now
};
_ctx.Things.Add(thing);
await _context.SaveChangesAsync();

await _blobService.Upload(data.File, $"{thing.Id}.jpg");
var thing = new Thing {
Name = data.Name,
Count = data.Count,
Date = DateTime.Now
};
_ctx.Things.Add(thing);
await _context.SaveChangesAsync();

await _blobService.Upload(data.File, $"{thing.Id}.jpg");
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.