Skip to content
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
Open

Posting Django FileFields before they're saved #18

barraponto opened this issue Sep 4, 2014 · 0 comments

Comments

@barraponto
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant