pass post params to WebClient.UploadFileAsync

对着背影说爱祢 提交于 2019-12-08 06:17:28

问题


hello i have a simple file upload with just one extra post parameter which is imgtitle.
it's used to rename the image after it's been transferred to the upload location on the server.
PHP:

<?php   
    $imgtitle = $_POST['title'];

    $current_image=$_FILES['file']['name'];
    $extension = substr(strrchr($current_image, '.'), 1);
    $new_image = $imgtitle. "." . $extension;
    $destination="uploads/".$new_image;
    $action = copy($_FILES['file']['tmp_name'], $destination);

    echo "--".$imgtitle."--";
?>

the upload works fine here.
http://tnsatchat.heliohost.org/tnsatchat/upload/upload.html
/upload/uploads/abcd.jpg

what i want to do is make a simple vb.net app which would allow me to upload the file/image
i'm using WebClient to do so.
but i'm having some difficulties passing the imgtitle parameter. here's my code

Dim ur = New Uri("http://tnsatchat.heliohost.org/tnsatchat/upload/upload.php?title=testname")
wc.UploadFileAsync(ur, "POST", "C:\testimage.jpg")

the upload is working i.e the file is there .. but with an empty name !!
/upload/uploads/.jpg
".jpg" is supposed to be "testname.jpg" but i guess the PHP is not getting that parameter.
any hints please !
edit:
i used the QueryString property

Dim ur = New Uri("http://tnsatchat.heliohost.org/tnsatchat/upload/upload.php")
Dim col = New Collections.Specialized.NameValueCollection
col.Add("title", "testname")
wc.QueryString = col
wc.UploadFileAsync(ur, "POST", "C:\testimage.jpg")

but with no better luck !!

来源:https://stackoverflow.com/questions/4615507/pass-post-params-to-webclient-uploadfileasync

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!