You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having issues when trying to POST Django FileFields files before they're saved. I'm trying to post them during a model save override (to get extra data). So in MyModel.save override it looks like this:
class MyModel(models.Model):
image = models.ImageField()
def save(self, *args, **kwargs):
res = unirest.post(url, headers=headers, params={
"image_request[image]": self.image.file
})
# @todo: add some field from res.body to my model.
super(MyModel, self).save(*args, **kwargs)
Problem is, before the model is saved, self.image.file is either an instance of InMemoryUploadedFile or TemporaryUploadedFile. When I have the latter (or after model is saved), I have to pass in open(self.image.file.path), as self.image.file.open() won't work. I wonder why.
The text was updated successfully, but these errors were encountered:
I'm having issues when trying to
POST
Django FileFields files before they're saved. I'm trying to post them during a model save override (to get extra data). So inMyModel.save
override it looks like this:Problem is, before the model is saved,
self.image.file
is either an instance of InMemoryUploadedFile or TemporaryUploadedFile. When I have the latter (or after model is saved), I have to pass inopen(self.image.file.path)
, asself.image.file.open()
won't work. I wonder why.The text was updated successfully, but these errors were encountered: