如何以编程方式将照片上传到图像托管服务器? [英] How to upload photos to a image hosting server programmatically?

查看:123
本文介绍了如何以编程方式将照片上传到图像托管服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想知道如何通过python或java(python首选)以编程方式将图片上传到图片托管网站。
该网站只通过网站上的上传按钮,即只有http访问权限,不提供ftp访问权限。
现在我不想要任何代码......我只是想弄清楚如果你可以指引我朝着正确的方向发展它会有所帮助。

Hi guys I was wondering how does one upload pics to a image hosting site programmatically through python or java (python preferred). The site gives no ftp access just through a upload button on the site i.e only http access. Now I don't want any code here..I just cant figure out how to start out if u can guide me in the right direction it will be helpful.

    <form method="post" name="" enctype="multipart/form-data" action="process.php" onsubmit="return validateForm(this)">
<input type="hidden" value="0" id="theValue">
<div id="myDiv">
    <input type="file" name="imagefile[]" size="27"><br><br>  
    <input type="file" name="imagefile[]" size="27"><br><br> 
    <input type="file" name="imagefile[]" size="27"><br><br> 
    <input type="file" name="imagefile[]" size="27"><br><br> 
    <input type="file" name="imagefile[]" size="27"><br><br>  
    <input type="hidden" name="MAX_FILE_SIZE" value="2097152">
</div>
<p><a href="javascript:;" onclick="addElement();">Upload more</a></p>
<input type="submit" value="Upload" name="upload">
<p></p>
</form>

网络表单。

推荐答案

*******************************



注意:这个答案自写完以来已经过时了。使用请求库。



http://docs.python-requests.org/en/latest/

*******************************

ATTENTION: This answer is outdated since the time it was written. Use requests library.

http://docs.python-requests.org/en/latest/

这是一个代码示例,对我来说正常。它使用MultipartPostHandler上传文件。

This is a code sample that "just works" for me. It uses MultipartPostHandler for uploading files.

import urllib2
import MultipartPostHandler

params = {'file':open( "FILENAME.JPG" , 'rb')}
opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)
urllib2.install_opener(opener)
req = urllib2.Request( "PROCESS.PHP" , params)
text_response = urllib2.urlopen(req).read().strip()

可以在 http://pypi.python.org上找到MultipartPostHandler。 /pypi/MultipartPostHandler/0.1.0

这篇关于如何以编程方式将照片上传到图像托管服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆