fixed image import in URL import

This commit is contained in:
vabene1111
2024-12-22 13:18:46 +01:00
parent 55ee575c9c
commit 3f7c22cfe0
2 changed files with 19 additions and 8 deletions

View File

@@ -48,11 +48,20 @@ export function useFileApi() {
})
}
function updateRecipeImage(recipeId: number, file: File|null){
/**
* update a recipes image either by a given file or given url
* @param recipeId ID of recipe to update
* @param file file object to upload or null to delete image (if no imageUrl is given)
* @param imageUrl url of an image to download by server
*/
function updateRecipeImage(recipeId: number, file: File|null, imageUrl?: string){
let formData = new FormData()
if (file != null) {
formData.append('image', file)
}
if (imageUrl) {
formData.append('image_url', imageUrl)
}
return fetch(getDjangoUrl(`api/recipe/${recipeId}/image/`), {
method: 'PUT',