def upload_asset(req, user, content_type):
            asset_manager = AssetManager()

            if content_type == 'application/json':
                data = json.loads(req.body)
                resource = asset_manager.upload_asset(user, data)
            else:
                data = json.loads(req.POST['json'])
                f = req.FILES['file']
                resource = asset_manager.upload_asset(user, data, file_=f)

            return resource, data
    def create(self, request):
        """
        Uploads a new downloadable digital asset
        :param request:
        :return: 201 Created, including the new URL of the asset in the location header
        """

        user = request.user
        profile = user.userprofile
        content_type = get_content_type(request)[0]

        if 'provider' not in profile.get_current_roles() and not user.is_staff:
            return build_response(request, 403,
                                  "You don't have the seller role")

        asset_manager = AssetManager()
        try:
            if content_type == 'application/json':
                data = json.loads(request.body)
                resource = asset_manager.upload_asset(user, data)
            else:
                data = json.loads(request.POST['json'])
                f = request.FILES['file']
                resource = asset_manager.upload_asset(user, data, file_=f)

        except ConflictError as e:
            return build_response(request, 409, unicode(e))
        except Exception as e:
            return build_response(request, 400, unicode(e))

        location = resource.get_url()

        # Fill location header with the URL of the uploaded digital asset
        response = HttpResponse(json.dumps({
            'content': location,
            'contentType': data['contentType'],
            'id': resource.pk,
            'href': resource.get_uri()
        }),
                                status=200,
                                mimetype='application/json; charset=utf-8')

        response['Location'] = location
        return response
    def create(self, request):
        """
        Uploads a new downloadable digital asset
        :param request:
        :return: 201 Created, including the new URL of the asset in the location header
        """

        user = request.user
        profile = user.userprofile
        content_type = get_content_type(request)[0]

        if "provider" not in profile.get_current_roles() and not user.is_staff:
            return build_response(request, 403, "You don't have the seller role")

        asset_manager = AssetManager()
        try:
            if content_type == "application/json":
                data = json.loads(request.body)
                location = asset_manager.upload_asset(user, data)
            else:
                data = json.loads(request.POST["json"])
                f = request.FILES["file"]
                location = asset_manager.upload_asset(user, data, file_=f)

        except ConflictError as e:
            return build_response(request, 409, unicode(e))
        except Exception as e:
            return build_response(request, 400, unicode(e))

        # Fill location header with the URL of the uploaded digital asset
        response = HttpResponse(
            json.dumps({"content": location, "contentType": data["contentType"]}),
            status=200,
            mimetype="application/json; charset=utf-8",
        )

        response["Location"] = location
        return response