New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Posting Django FileFields before they're saved #18

Open
barraponto opened this Issue Sep 4, 2014 · 0 comments

Comments

Projects
None yet
1 participant
@barraponto

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment