当我尝试将文件上传到ftp服务器时,我收到错误.服务器是远程服务器,但它提供ftp访问.这是我正在使用的代码
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fileuploaddemo;
import org.apache.commons.net.ftp.FTPClient;
import java.io.FileInputStream;
import java.io.IOException;
public class FileUploadDemo {
public static void main(String[] args) {
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect("ftp.adress.comlu.com");
client.login("username", "mypass");
//
// Create an InputStream of the file to be uploaded
//
String filename = "D:/xxx/screen0.png";
fis = new FileInputStream(filename);
//
// Store file to server
//
client.storeFile(filename, …Run Code Online (Sandbox Code Playgroud) 我想上传个人资料图片.图像未上传.它在/ profile /中给出错误AttributeError
'list'对象没有'startswith'属性
def userDetail(request):
current_user = request.user
if(request.method == 'POST'):
form = UserDetailDataForm(request.POST, request.FILES)
if(form.is_valid()):
profileImg = request.FILES['profileImg']
try:
userprofile = UserDetail.objects.get(user_id = current_user.id)
if userprofile:
userprofile.profileImg = profileImg
userprofile.save()
context = {'username': current_user.username, 'image' : userprofile.profileImg, 'MEDIA_ROOT': settings.MEDIA_ROOT}
return render_to_response('user_profile.html', context)
else:
form = UserDetailDataForm()
return render_to_response('profile.html', {'form': form})
Run Code Online (Sandbox Code Playgroud)
Models.py
profileImg = models.ImageField(upload_to='/images/',blank=True, null=True,default="images/default-profile.jpg")
设置文件:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MEDIA_ROOT = [
os.path.join(BASE_DIR, 'firstapp/static/'),]
Run Code Online (Sandbox Code Playgroud)
完整StackTrace:
Environment:
Request Method: POST
Request URL: http://localhost:8000/profile/
Django Version: 1.10.5
Python Version: 2.7.12 …Run Code Online (Sandbox Code Playgroud) 在如何使用Cucumber/Capybara在页面上找到图像的解决方案的评论中,有人问:
我似乎无法想象如何使用Dragonfly生成的URL.它们看起来像这样:/media/BAh_some_long_string_AwIw/12_11_52_810_5x5.jpg?s=7e360000,其中5x5.jpg是我的文件名.我尝试过类似:// img [@src ="/ media//#{image}?s =*"]但它不起作用.有什么提示吗?- Ramon Tayag 2月25日凌晨 4点18分
我有一个类似的问题,只是更糟糕 - 在我的情况下,生成的图像路径甚至不包括(jpg | png | gif)文件名,它们只有这些非常长的ID:
<img src="/media/BAhbB1sHOgZmSSIdNGQ4MTEyOGU3ZjViZmQwZTQ4MDAwMDAyBjoGRVRbCDoGcDoKdGh1bWJJIg0yMDB4MjAwIwY7BlQ" />
Run Code Online (Sandbox Code Playgroud)
(使用蜻蜓和mongo/gridfs)
这些路径渲染得很好,但我无法弄清楚如何在Cucumber/Capybara步骤中找到它们:P
有任何想法吗?我查看了Dragonfly的功能,但是他们只测试了图像本身的渲染,而没有检测到它在html页面中的存在.
我正在尝试使用带有多个参数作为请求正文的 axio 将多个图像上传到服务器。基本上下面是本机android中的请求,它试图在本机反应中做到这一点。
@Headers(HTTPService.NEEDS_AUTH_HEADER)
@Multipart
@POST("/api/post")
Call<Post> create(
@Part("title") RequestBody title,
@Part("content") RequestBody content,
@Part("location") RequestBody location,
@Part("category") RequestBody category,
@Part("captions") List<RequestBody> captions,
@Part List<MultipartBody.Part> parts
);
Run Code Online (Sandbox Code Playgroud)
这就是我试图做的反应:
const config = {
method: 'post',
headers: {
'NEEDS_AUTH': true,
Accept: 'application/json',
'Content-type': undefined
},
formDataArray,
url: PATH_API_CREATE_POST,
data: {
title: postTitle,
content: postContent,
location: locationId,
category: categoryId,
}
}
axios(config).then(res => console.log('create post ', res)).catch(err => console.log('create post err', err.response))
Run Code Online (Sandbox Code Playgroud)
这是 formDataArray :
photos.forEach(element => {
let formdata = new FormData(); …
我正在尝试从单个表单中提取图像和文本数据。我尝试使用 formdata.get('image') 来获取用户选择的图像,但它不起作用,因为我在服务器上收到未定义的值。我想知道使用 formdata 或任何其他方法获取用户在表单中选择的图像的适当方法,谢谢。
表格
<form id = "register" class = "edit-note" enctype = "multipart/form-data">
<div>
<label>Heading:</label>
<input type = "text" name = "heading" placeholder = "<%= Note[0].heading %>" id = "heading">
</div>
<div>
<label>Small Text:</label>
<input type = "text" name = "stext" placeholder = "<%= Note[0].smallText %>" id = "stext">
</div>
<div>
<label>Featured Image:</label>
<img src = "<%= Note[0].image %>" height = "110px" width = "132px">
<input type = "file" name = "image" id = "fimage">
</div>
<div> …Run Code Online (Sandbox Code Playgroud) 我正在使用此功能将文件上传到磁盘:
$talentFolderPath = 'C:/xampp/htdocs/project/';
public function uploadToDisk($talentFolderPath, $filename)
{
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination($talentFolderPath);
$adapter->addFilter( 'Rename',array('target' => $talentFolderPath."/".$filename) );
if ($adapter->receive()) {
$message = "success";
} else {
$message = "fail";
}
return $message;
}
Run Code Online (Sandbox Code Playgroud)
我收到这条消息:
消息:无法重命名文件'C:\ xampp\tmp\php3226.tmp'.它已经存在.
有什么想法发生了什么?
谢谢.
如何仅在 WordPress 中严格限制图像的上传大小?如果您进入“设置”页面,它会告诉您上传文件类型和最大上传大小。我想保持除图像之外的所有最大上传大小一致。
我想通过网址上传图片
'C:\wamp\www\reelstubs\app\webroot\img\movies\0bf522bb76777ba43393b9be5552b263.jpg'
Run Code Online (Sandbox Code Playgroud)
但我想要一个类似的阵列
array(
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => (int) 4,
'size' => (int) 0
),
Run Code Online (Sandbox Code Playgroud)
请建议我如何获得?
image-upload ×8
php ×2
axios ×1
capybara ×1
cucumber ×1
django ×1
fetch ×1
file-upload ×1
forms ×1
image ×1
java ×1
java-server ×1
javascript ×1
python ×1
react-native ×1
reactjs ×1
upload ×1
wordpress ×1