def parse(self, stream, media_type=None, parser_context=None): """ Parses the incoming bytestream as a multipart encoded form, and returns a DataAndFiles object. `.data` will be a `QueryDict` containing all the form parameters. `.files` will be a `QueryDict` containing all the form files. """ parser_context = parser_context or {} request = parser_context["request"] encoding = parser_context.get("encoding", settings.DEFAULT_CHARSET) meta = request.META.copy() meta["CONTENT_TYPE"] = media_type upload_handlers = request.upload_handlers try: parser = DjangoMultiPartParser(meta, stream, upload_handlers, encoding) data, files = parser.parse() return DataAndFiles( underscoreize(data, **api_settings.JSON_UNDERSCOREIZE), underscoreize(files, **api_settings.JSON_UNDERSCOREIZE), ) except MultiPartParserError as exc: raise ParseError("Multipart form parse error - %s" % str(exc))
def parse(self, stream, media_type=None, parser_context=None): """ Parses the incoming bytestream as a multipart encoded form, and returns a DataAndFiles object. `.data` will be a `QueryDict` containing all the form parameters, and JSON decoded where available. `.files` will be a `QueryDict` containing all the form files. """ parser_context = parser_context or {} request = parser_context['request'] encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET) meta = request.META.copy() meta['CONTENT_TYPE'] = media_type upload_handlers = request.upload_handlers try: parser = DjangoMultiPartParser(meta, stream, upload_handlers, encoding) data, files = parser.parse() for key in data: if data[key]: try: data[key] = json.loads(data[key]) except ValueError: pass return DataAndFiles(data, files) except MultiPartParserError as exc: raise ParseError('Multipart form parse error - %s' % six.text_type(exc))
def parse(self, stream): """ Returns a 2-tuple of `(data, files)`. `data` will be a :class:`QueryDict` containing all the form parameters. `files` will be a :class:`QueryDict` containing all the form files. """ upload_handlers = self.view.request._get_upload_handlers() django_parser = DjangoMultiPartParser(self.view.request.META, stream, upload_handlers) return django_parser.parse()
def parse(self, stream): """ Returns a 2-tuple of `(data, files)`. `data` will be a :class:`QueryDict` containing all the form parameters. `files` will be a :class:`QueryDict` containing all the form files. """ upload_handlers = self.view.request._get_upload_handlers() try: django_parser = DjangoMultiPartParser(self.view.request.META, stream, upload_handlers) except MultiPartParserError, exc: raise ErrorResponse(status.HTTP_400_BAD_REQUEST, {'detail': 'multipart parse error - %s' % unicode(exc)})
def parse(self, stream, media_type=None, parser_context=None): parser_context = parser_context or {} request = parser_context['request'] encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET) meta = request.META.copy() meta['CONTENT_TYPE'] = media_type upload_handlers = request.upload_handlers parsed = [] try: parser = DjangoMultiPartParser(meta, stream, upload_handlers, encoding) _, files = parser.parse() for file in files.values(): parsed.append({'image': file}) return parsed except MultiPartParserError as e: raise ParseError(str(e))
def parse(self, stream, media_type=None, parser_context=None): """ Returns a DataAndFiles object. `.data` will be a `QueryDict` containing all the form parameters. `.files` will be a `QueryDict` containing all the form files. """ parser_context = parser_context or {} request = parser_context['request'] meta = request.META upload_handlers = request.upload_handlers try: parser = DjangoMultiPartParser(meta, stream, upload_handlers) data, files = parser.parse() return DataAndFiles(data, files) except MultiPartParserError, exc: raise ParseError('Multipart form parse error - %s' % unicode(exc))
def parse(self, stream, media_type=None, parser_context=None): """ Returns a DataAndFiles object. `.data` will be a `QueryDict` containing all the form parameters. `.files` will be a `QueryDict` containing all the form files. """ parser_context = parser_context or {} request = parser_context['request'] encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET) meta = request.META upload_handlers = request.upload_handlers try: parser = DjangoMultiPartParser(meta, stream, upload_handlers, encoding) data, files = parser.parse() return DataAndFiles(data, files) except MultiPartParserError as exc: raise ParseError('Multipart form parse error - %s' % six.u(exc))
def parse(self, stream, media_type=None, parser_context=None): ''' Parses the incoming bytestream as a multipart encoded form, and returns a DataAndFiles object. `.data` will be a `QueryDict` containing all the form parameters. `.files` will be a `QueryDict` containing all the form files. ''' parser_context = parser_context or {} request = parser_context['request'] encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET) meta = request.META.copy() meta['CONTENT_TYPE'] = media_type upload_handlers = request.upload_handlers try: parser = DjangoMultiPartParser(meta, stream, upload_handlers, encoding) data, files = parser.parse() return DataAndFiles(decamelize(data), decamelize(files), ) except MultiPartParserError as err: raise ParseError(f'Multipart form parse error - {err}')
def parse(self, stream, media_type=None, parser_context=None): parser_context = parser_context or {} request = parser_context['request'] encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET) meta = request.META.copy() meta['CONTENT_TYPE'] = media_type upload_handlers = request.upload_handlers try: parser = DjangoMultiPartParser(meta, stream, upload_handlers, encoding) data, files = parser.parse() result = parsers.DataAndFiles(data, files) data = {} data = json.loads(result.data["data"]) for key, value in result.files.items(): data = compile_payload(data, key.split("."), value) return data except MultiPartParserError as exc: raise ParseError('Multipart form parse error - %s' % six.text_type(exc))
def parse(self, stream, media_type=None, parser_context=None): """Parse the incoming bytestream. Parses the incoming bytestream as a multipart encoded form and returns a DataAndFiles object. `.data` will be a `QueryDict` containing all the form parameters, and JSON decoded where available. `.files` will be a `QueryDict` containing all the form files. :param (bytes) stream: Incoming byte stream. :param (str) media_type: Media Type. :param (dict) parser_context: Context. """ parser_context = parser_context or {} request = parser_context["request"] encoding = parser_context.get("encoding", settings.DEFAULT_CHARSET) meta = request.META.copy() meta["CONTENT_TYPE"] = media_type upload_handlers = request.upload_handlers try: parser = DjangoMultiPartParser(meta, stream, upload_handlers, encoding) data, files = parser.parse() # get a dict of data to make it mutable _data = data.dict() for key in _data: if _data[key]: try: _data[key] = json.loads(_data[key]) except ValueError: pass return DataAndFiles(_data, files) except MultiPartParserError as exc: raise ParseError("Multipart form parse error - %s" % str(exc))