Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curl_formadd() is unavailable #112

Closed
sector-f opened this issue Jun 5, 2016 · 12 comments
Closed

curl_formadd() is unavailable #112

sector-f opened this issue Jun 5, 2016 · 12 comments

Comments

@sector-f
Copy link

sector-f commented Jun 5, 2016

I'm currently trying to write a file upload program. This requires sending data to a form (analogous to curl -F from the command line). I've been told that the equivalent function in native libcurl is curl_formadd(), but this function is commented out in the curl_sys crate. And, of course, this means there's no corresponding function in the curl crate.

@alexcrichton
Copy link
Owner

Ah yes, right! I had some difficulty initially with some CI and decided to not bind them in the first pass, I'll take a look now at binding them and see how it goes.

@alexcrichton
Copy link
Owner

Ok, lemme know if that works for you!

@sector-f
Copy link
Author

sector-f commented Jun 6, 2016

Well, it looks good...but I honestly don't know enough about curl (yet) to tell if it works.

What's the correct way to take a PathBuf and then upload the corresponding file to a form?

@alexcrichton
Copy link
Owner

I believe that would look like this

@sector-f
Copy link
Author

sector-f commented Jun 7, 2016

Seems like a step in the right direction, but I can't get it to work—though I'm willing to bet it's my fault. Here's my function:

fn upload_files(url: String, files: Vec<PathBuf>, _concurrent_uploads: u32) {
    curl::init();
    let mut handle = Easy::new();
    for file in &files {
        let mut form = Form::new();
        form.part("file").file(&file).add().unwrap();

        handle.url(&url).unwrap();
        handle.httppost(form).unwrap();

        handle.write_function(|a| {
            Ok(stdout().write(a).unwrap())
        }).unwrap();

        handle.perform().unwrap();
    }
}

However, handle.perform() is returning an Err, [26] Failed to open/read local data from file/application

@alexcrichton
Copy link
Owner

Hm and you're sure all those files exist? You may be able to use strace as well to figure out which syscall curl is issuing that's failing

@sector-f
Copy link
Author

sector-f commented Jun 7, 2016

Hm, it apparently works with an absolute path but not with a relative one.

@alexcrichton
Copy link
Owner

Hm that's odd, the test I have is using a relative path...

@sector-f
Copy link
Author

sector-f commented Jun 7, 2016

Actually, correction: ./foo.jpg works but foo.jpg does not.

@alexcrichton
Copy link
Owner

Oh weird, do you have an example that doesn't work in terms of a concrete setup?

@sector-f
Copy link
Author

sector-f commented Jun 7, 2016

Oh, dear. It just got weirder.

./target/debug/curl_main room.jpg (what I'd been trying) fails. So I just copied another picture to the directory.

./target/debug/curl_main ocean.jpg succeeds.

@sector-f
Copy link
Author

sector-f commented Jun 7, 2016

Just for posterity: the above problem was caused by a lack of null terminators.

This was fixed in 5f9fe7b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants