Code Monkey home page Code Monkey logo

Comments (5)

drahnr avatar drahnr commented on June 18, 2024

The first idea was to use

request.headers_mut().set(ContentLength(meta_json.len() as u64 + size_srpm as u64));

but that results in

failed to write whole buffer

when spawning the multipart struct

from multipart.

drahnr avatar drahnr commented on June 18, 2024

The following produces the same error:

    let mut request = Request::with_connector(Method::Post, url, &connector)
   					.chain_err(||"Failed to create POST request")?;
    request.headers_mut().set(
			ContentType(
		 		Mime(
		 			TopLevel::Multipart, SubLevel::Ext("form-data".into()),
		 			vec![(Attr::Ext("boundary".into()), Value::Ext(boundary.into()))]
		 			)
		 		)
		 	);
    request.headers_mut().set(ContentLength(meta_json.len() as u64 + size_srpm as u64));

    let mut multipart = Multipart::from_request(request).chain_err(||"Failed to create multipart request")?;

from multipart.

drahnr avatar drahnr commented on June 18, 2024

Total length is 1260944 [ bytes ] which is not too much to allocate ..

from multipart.

abonander avatar abonander commented on June 18, 2024

The ContentLength value has to be the whole size of the body, including multipart boundaries and field headers.

If you use Multipart::from_request_sized() it will set the ContentLength header correctly, though the implementation is incredibly naive; it just writes the whole request to an in-memory buffer to get the length that way and then writes it out to the stream in one fell swoop.

from multipart.

drahnr avatar drahnr commented on June 18, 2024

Understood, I ended up doing exactly that.

I think there is no other way around that since the headers are only to be written with Request where body is only to be written with Request given hyper's implementation.

from multipart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.