会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132837个问题

老师这是怎么回事,后台也没有报错

package com.bjsxt.ego.manager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.bjsxt.ego.beans.PictureResult;
import com.bjsxt.manager.service.ManagerItemService;

@Controller
public class ItemImageController {

	@Autowired
	private ManagerItemService managerItemService;
	
	/**
	 * 处理图片上传请求
	 */
	@RequestMapping(value="pic/upload",produces=MediaType.APPLICATION_JSON_VALUE
			+";charset=UTF-8")
	@ResponseBody
	public PictureResult picUpLoad(MultipartFile uploadFile) {
		return managerItemService.uploadItemPic(uploadFile);
	}
	
}
package com.bjsxt.ego.beans;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;

public class FtpUtils {

	public static void main(String[] args)  {
		
		/**
		 * 完成图片上传,通过ftp将图片上传到图片服务器
		 */
		
		String hostname = "192.168.86.135";
		int port = 21;
		String username = "ftpuer";
		String password = "xuxiaoqin";
		String pathname = "/home/ftpuser/jd";
		String remote="demo.jpg";
		InputStream local =null;
		try {
			local = new FileInputStream("D:/笔记/第八章/第四章/02 软件/pic/1.jpg");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		FtpUtils a = new FtpUtils();
		
		a.uploadFile(hostname, port, username, password, pathname, remote, local);
				
		
	}
	
	public static boolean uploadFile(String hostname, 
			int port, String username, 
			String password, String pathname,
			String remote,InputStream local) {
		
		Boolean flag = false;
		try {
			//创建FtpClient对象
			FTPClient client = new FTPClient();
			//建立和ftp服务器的连接
			client.connect(hostname,port);
			//登录ftp服务器
			client.login(username, password);
			//设置上传的文件的类型
			client.setFileType(FTP.BINARY_FILE_TYPE);
			//切换工作目录,文件上传后保存到那个目录
			if(!client.changeWorkingDirectory(pathname)){
				if(client.makeDirectory(pathname)){
					client.changeWorkingDirectory(pathname);
				}
			}
			
			local = new FileInputStream("D:/笔记/第八章/第四章/02 软件/pic/1.jpg");
			//实现文件上传
			client.storeFile(remote, local);
			 
			local.close();
			
			client.logout();
			client.disconnect();
			flag = true;
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return flag;
	}
	
	
}
@Override
	public PictureResult uploadItemPic(MultipartFile file) {
		// TODO Auto-generated method stub
		
		Boolean flag = null;
		String fileName = null;
		
		try {
			//获得信息的文件的名字
			fileName = IDUtils.genImageName();
			//获得上传的文件的原始名字
			String oriName = file.getOriginalFilename();
			//获得文件扩展名
			String ext = oriName.substring(oriName.lastIndexOf("."));
			
			fileName = fileName+ext;
			
			InputStream local = file.getInputStream();
			
			//实现文件上传到ftp
			flag = FtpUtils.uploadFile(FTP_HOST, FTP_PORT, FTP_USERNAME, 
					FTP_PASSWORD, FTP_PATH, fileName, local);
			
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			flag = false;
		}
		
		PictureResult result = null;
		
		if(flag) {
			result = new PictureResult();
			result.setError(0);
			result.setUrl(IMAGE_HTTP_PATH+"/"+fileName);
			result.setMessage("ok");
			System.out.println(1);
		}else {
			result = new PictureResult();
			result.setError(1);
			result.setUrl("url");
			result.setMessage("error");
		}
		
		return result;
	}



ego.zip

image.png

image.png

JAVA 全系列/(旧的隐藏)第八阶段:电商高级项目_架构/编码/电商ego-使用VSFTPD_Nginx完成商品新增 10187楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/反射技术(旧) 10189楼
WEB前端全系列/第二十阶段:Vue2企业级项目(旧)/疫情动态实时播报 10192楼
JAVA 全系列/第一阶段:JAVA 快速入门/JAVA入门和背景知识 10193楼
WEB前端全系列/第七阶段:ECMAScript6新特性模块/ES6 第一部分 10195楼
JAVA 全系列/第五阶段:JavaWeb开发/Web实战案例 10196楼
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 10197楼
JAVA 全系列/第十三阶段:高性能数据处理、NoSQL、分库分表/MyCat 10198楼
Python 全系列/第五阶段:数据库编程/mysql的使用 10199楼

shop_env.zip

我这个也是直接跳try到except了   debug几次 ,password改pwd也看了(这个希望能说明白点,)没找到问题在哪   

Python 全系列/第九阶段:Flask百战电商后台系统/Flask百战电商后台项目 10200楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637