Search code examples
pythondjangoapiresttastypie

How patch resource with file


I have this model and resource for user-profile

class Profile(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(blank=False, null=False, unique=True)
    avatar = models.ImageField(blank=True, null=True)

class ProfileResource(ModelResource):
    class Meta:
        queryset = Profile.objects.all()
        resource_name = 'profiles'
        allowed_methods = ['get', 'patch']

When I had try to patch this resource, i got the exception:

RawPostDataException("You cannot access body after reading from request's data stream")

For sending test data I use the chrome-extention

send the PATHC query to my resource


Solution

  • This is related to the file upload that you are trying to do. The content type cannot be processed in this way, you should convert the file to base64 in order to do that.

    Check this Github issue for further information on how you should proceed on POST (or PATCH) files to your resource.

    Also, this stack is related to your problem.