Django REST Framework image upload

you can create separate endpoint for uploading images, it would be like that: class ProductViewSet(BaseViewSet, viewsets.ModelViewSet): queryset = Product.objects.all() serializer_class = ProductSerializer @detail_route(methods=[‘post’]) def upload_docs(request): try: file = request.data[‘file’] except KeyError: raise ParseError(‘Request has no resource file attached’) product = Product.objects.create(image=file, ….) you can go around that solution — update: this’s how to upload from … Read more

Resize image in PHP

You need to use either PHP’s ImageMagick or GD functions to work with images. With GD, for example, it’s as simple as… function resize_image($file, $w, $h, $crop=FALSE) { list($width, $height) = getimagesize($file); $r = $width / $height; if ($crop) { if ($width > $height) { $width = ceil($width-($width*abs($r-$w/$h))); } else { $height = ceil($height-($height*abs($r-$w/$h))); } … Read more