Java-Class-I:org.springframework.web.mutipart.MutipartFile
| ylbtech-Java-Class-I:org.springframework.web.mutipart.MutipartFile |
| 1.返回顶部 |
| 2.返回顶部 |
@ApiOperation(value = "机构更新信息")
@PostMapping("/detail/update")
public Result detailUpdate(HttpServletRequest request,Organization organization, MultipartFile[] file) {
//机构id
String orgId = TokenUtils.getOrganizationId(request, jwtUtil);
organization.setOrganizationID(orgId); String fileUrl = null; try {
for (MultipartFile mf : file) {
if (!mf.isEmpty()) {
//获取文件全名
String fileName = mf.getOriginalFilename();
//扩展名
String extensionName = fileName.substring(fileName.lastIndexOf(".") + 1);
//新文件名
String newFileName = String.valueOf(System.currentTimeMillis()) + "." + extensionName;
fileUrl = CosClientUtil.uploadFile(mf.getInputStream(), newFileName, orgId);
//默认一张
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} organization.setImageUrl(fileUrl);
int i = organizationService.updateOrganization(organization);
if (i > 0) {
return ResultGenerator.genOkResult();
} else {
return ResultGenerator.genFailedResult();
}
}
| 3.返回顶部 |
| 4.返回顶部 |
/*
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ package org.springframework.web.multipart; import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path; import org.springframework.core.io.InputStreamSource;
import org.springframework.core.io.Resource;
import org.springframework.lang.Nullable;
import org.springframework.util.FileCopyUtils; /**
* A representation of an uploaded file received in a multipart request.
*
* <p>The file contents are either stored in memory or temporarily on disk.
* In either case, the user is responsible for copying file contents to a
* session-level or persistent store as and if desired. The temporary storage
* will be cleared at the end of request processing.
*
* @author Juergen Hoeller
* @author Trevor D. Cook
* @since 29.09.2003
* @see org.springframework.web.multipart.MultipartHttpServletRequest
* @see org.springframework.web.multipart.MultipartResolver
*/
public interface MultipartFile extends InputStreamSource { /**
* Return the name of the parameter in the multipart form.
* @return the name of the parameter (never {@code null} or empty)
*/
String getName(); /**
* Return the original filename in the client's filesystem.
* <p>This may contain path information depending on the browser used,
* but it typically will not with any other than Opera.
* @return the original filename, or the empty String if no file has been chosen
* in the multipart form, or {@code null} if not defined or not available
* @see org.apache.commons.fileupload.FileItem#getName()
* @see org.springframework.web.multipart.commons.CommonsMultipartFile#setPreserveFilename
*/
@Nullable
String getOriginalFilename(); /**
* Return the content type of the file.
* @return the content type, or {@code null} if not defined
* (or no file has been chosen in the multipart form)
*/
@Nullable
String getContentType(); /**
* Return whether the uploaded file is empty, that is, either no file has
* been chosen in the multipart form or the chosen file has no content.
*/
boolean isEmpty(); /**
* Return the size of the file in bytes.
* @return the size of the file, or 0 if empty
*/
long getSize(); /**
* Return the contents of the file as an array of bytes.
* @return the contents of the file as bytes, or an empty byte array if empty
* @throws IOException in case of access errors (if the temporary store fails)
*/
byte[] getBytes() throws IOException; /**
* Return an InputStream to read the contents of the file from.
* <p>The user is responsible for closing the returned stream.
* @return the contents of the file as stream, or an empty stream if empty
* @throws IOException in case of access errors (if the temporary store fails)
*/
@Override
InputStream getInputStream() throws IOException; /**
* Return a Resource representation of this MultipartFile. This can be used
* as input to the {@code RestTemplate} or the {@code WebClient} to expose
* content length and the filename along with the InputStream.
* @return this MultipartFile adapted to the Resource contract
* @since 5.1
*/
default Resource getResource() {
return new MultipartFileResource(this);
} /**
* Transfer the received file to the given destination file.
* <p>This may either move the file in the filesystem, copy the file in the
* filesystem, or save memory-held contents to the destination file. If the
* destination file already exists, it will be deleted first.
* <p>If the target file has been moved in the filesystem, this operation
* cannot be invoked again afterwards. Therefore, call this method just once
* in order to work with any storage mechanism.
* <p><b>NOTE:</b> Depending on the underlying provider, temporary storage
* may be container-dependent, including the base directory for relative
* destinations specified here (e.g. with Servlet 3.0 multipart handling).
* For absolute destinations, the target file may get renamed/moved from its
* temporary location or newly copied, even if a temporary copy already exists.
* @param dest the destination file (typically absolute)
* @throws IOException in case of reading or writing errors
* @throws IllegalStateException if the file has already been moved
* in the filesystem and is not available anymore for another transfer
* @see org.apache.commons.fileupload.FileItem#write(File)
* @see javax.servlet.http.Part#write(String)
*/
void transferTo(File dest) throws IOException, IllegalStateException; /**
* Transfer the received file to the given destination file.
* <p>The default implementation simply copies the file input stream.
* @since 5.1
* @see #getInputStream()
* @see #transferTo(File)
*/
default void transferTo(Path dest) throws IOException, IllegalStateException {
FileCopyUtils.copy(getInputStream(), Files.newOutputStream(dest));
} }
| 5.返回顶部 |
| 6.返回顶部 |
![]() |
作者:ylbtech 出处:http://ylbtech.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |
Java-Class-I:org.springframework.web.mutipart.MutipartFile的更多相关文章
- SSM报错:No converter found for return value of type: class java.util.ArrayList at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverter
我使用的是SSM框架,是在编写测试RESTFUL接口的时候出现, @RequestMapping(value = "/selectAll", method = RequestMet ...
- Spring MVC报异常:org.springframework.web.util.NestedServletException: Request processing failed
在使用SpringMVC绑定基本类型(如String,Integer等)参数时,应通过@RequestParam注解指定具体的参数名称,否则,当源代码在非debug模式下编译后,运行时会引发Handl ...
- 项目maven update 后启动项目出现导常:org.springframework.web.context.ContextLoaderListener
导常:org.springframework.web.context.ContextLoaderListener 1. 右键单击工程项目 ->点击 properties2. 选择 Deploym ...
- Java-API-Package:org.springframework.web.bind.annotation
ylbtech-Java-API-Package:org.springframework.web.bind.annotation 1.返回顶部 1. @NonNullApi @NonNullField ...
- Java-Class-@I:org.springframework.web.bind.annotation.PostMapping
ylbtech-Java-Class-@I:org.springframework.web.bind.annotation.PostMapping 1.返回顶部 2.返回顶部 1. package ...
- Java-Class-@I:org.springframework.web.bind.annotation.RestController
ylbtech-Java-Class-@I:org.springframework.web.bind.annotation.RestController 1.返回顶部 2.返回顶部 1. pack ...
- Java-Class-@I:org.springframework.web.bind.annotation.RequestMapping
ylbtech-Java-Class-@I:org.springframework.web.bind.annotation.RequestMapping 1.返回顶部 2.返回顶部 1. pack ...
- Java-Class-@I:org.springframework.web.bind.annotation.RequestBody
ylbtech-Java-Class-@I:org.springframework.web.bind.annotation.RequestBody 1.返回顶部 2.返回顶部 1. package ...
- Java-Class-C:org.springframework.web.client.RestTemplate
ylbtech-Java-Class-C:org.springframework.web.client.RestTemplate 1.返回顶部 1. org.springframework.web.c ...
随机推荐
- express框架总结
1.express教程及api : http://www.runoob.com/nodejs/nodejs-express-framework.html 2.nodejs的express自动生成项目框 ...
- Docker Machine 管理-安装docker-machine(15)
前面我们的实验环境中只有一个 docker host,所有的容器都是运行在这一个 host 上的.但在真正的环境中会有多个 host,容器在这些 host 中启动.运行.停止和销毁,相关容器会通过网络 ...
- 【Spring Boot】Spring Boot项目设置多个配置文件,并在生产环境中的Tomcat设置对应的配置文件
1.修改Spring Boot项目配置文件 除了主配置文件,另外创建2个配置文件,注意命名要用application-*.properties 主配置文件中写入,使用dev作为开发配置 spring. ...
- (14)C++ 代码重用
valarray<,,,, };//进行高速的数字计算 int a= val.size();//返回包含元素个数 int b= val.sum();//元素总和 int c= val.max() ...
- MySQL-视图上进行增删改查
https://dev.mysql.com/doc/refman/5.7/en/view-updatability.html https://dev.mysql.com/doc/refman/8.0/ ...
- VTemplate模板引擎的使用--入门篇
1.什么是VTemplate模板引擎? 详细请点击这里. 2.怎样使用VTemplate模板引擎? 第1步: 下载VTemplate模板引擎的最新库文件(从这里下载),下载回来后将库文件引入到你的项目 ...
- Device Drivers
Types of Device Drivers Windows可能会有User-mode的驱动,但是我们只关注Kernel-Mode的驱动. WDM Drivers WDM是一种驱动模型,是比较常用的 ...
- 运维02 Shell基础命令(一)
Shell基础命令(一) Shell 教程 Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁.Shell 既是一种命令语言,又是一种程序设计语言. Shell 是指一种应 ...
- Python判断一个字符串中是否存在多个子串中的一个
在使用python的开发过程中,常常需要判断,字符串中是否存在子串的问题, 但判断一个字符串中是否存在多个字串中的一个时,如if (a or b) in c或者if x contains a|b|c| ...
- android中的原始资源的使用
原始资源可以放在两个地方: 1.位于/res/raw目录下,android SDK会处理该目录下的原始资源,android SDK会在R清单类中为该目录下的资源生成一个索引项. 2.位于/assets ...
