当前位置: 首页 > news >正文

商标设计网站排行网页设计模板html代码

商标设计网站排行,网页设计模板html代码,如何对网站做压力测试,上海 网站开发 工作室准备 确定好服务器端文件保存的位置确定好请求参数名&#xff08;前后端要保持一致的喔&#xff09;如果手机是通过usb连接到电脑的&#xff0c;需要执行一下&#xff1a; adb reverse tcp:8080 tcp:8080 AndroidManifest.xml的<application/>节点中加上: android:usesC…

准备

  • 确定好服务器端文件保存的位置
  • 确定好请求参数名(前后端要保持一致的喔)
  • 如果手机是通过usb连接到电脑的,需要执行一下:
    • adb reverse tcp:8080 tcp:8080
  • AndroidManifest.xml<application/>节点中加上:
    • android:usesCleartextTraffic="true"
  • 引入依赖:
    • implementation("com.google.net.cronet:cronet-okhttp:0.1.0")

开始

Android端

Activity(ComponentActivity)private lateinit var imagePicker: ActivityResultLauncher<PickVisualMediaRequest>override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)imagePicker = registerForActivityResult(ActivityResultContracts.PickVisualMedia()) {context.contentResolver.openInputStream(it)?.use {val file = File(File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "TempFiles").smartCreate(true), "Image_${currentTimeMillis}.png").smartCreate()it.copyTo(FileOutputStream(file))launch(Dispatchers.Main) { launch(Dispatchers.IO) { val clint = OkHttpClient()val requestBody = MultipartBody.Builder().apply {setType(MultipartBody.FORM)// 这个 "file" 是前后端参数名,保持一致,不然springboot报错addFormDataPart("file", imageFile!!.name, RequestBody.create(MediaType.parse("image/*"),imageFile))}.build()val responseBody = clint.newCall(Request.Builder().post(requestBody).url("http://localhost:8080/upload").build()).execute().body()logE { "${responseBody?.string()}" }}}}}
}inline val currentTimeMillis: Longget() = System.currentTimeMillis()fun File.smartCreate(isDir: Boolean = false): File {if (!exists()) {parentFile?.mkdirs()if (isDir) mkdir() else createNewFile()}return this
}

服务端(Spring Boot)

1.在application.properties文件中配置文件相关的参数

spring.servlet.multipart.max-request-size=50MB
spring.servlet.multipart.max-file-size=50MB# 上传的文件保存在哪个文件下,这里保存到项目文件夹下的upload文件夹
# 也可以指定其他文件夹,把路径复制上就行,比如 upload.file.path=C:\Users\Public\Pictures
upload.file.path=upload

2.写Controller方法

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;@RestController
public class TestController {@Value("${upload.file.path}")private String uploadPathStr;/*** 保持请求参数名一致* * @param file* @return*/@PostMapping("/upload")public @ResponseBody boolean upload(@RequestParam("file") MultipartFile file){if(file == null || file.isEmpty() || filename == null || filename.isEmpty())return false;try(InputStream inputStream = file.getInputStream()) {Path uploadPath = Paths.get(uploadPathStr);if(!uploadPath.toFile().exists())uploadPath.toFile().mkdirs();Files.copy(inputStream, Paths.get(uploadPathStr).resolve(file.getOriginalFilename()), StandardCopyOption.REPLACE_EXISTING);System.out.println("upload file , filename is "+file.getOriginalFilename() + ", filePath = " + Paths.get(uploadPathStr).resolve(file.getOriginalFilename()).toAbsolutePath().toString());return true;}catch (IOException e) {e.printStackTrace();return false;}}
}

运行调试即可…

http://www.hkea.cn/news/693916/

相关文章:

  • 找公司做网站怎么图片都要自己找百度推广官网电话
  • 网站小样用什么做seo外链平台热狗
  • 建站点的步骤sem是什么
  • 深圳专业做网站的衡水网站优化推广
  • 徐汇科技网站建设2345中国最好的网址站
  • 邢台论坛吧百度seo收录软件
  • 做国外服务器网站吗怎么让百度搜索靠前
  • 做动态图网站有哪些自建站怎么推广
  • web网站开发课程设计报告seo技术培训沈阳
  • 会宁网站建设公司网站优化助手
  • 网站设计制作体会2023年5月最新疫情
  • 月亮湾设计有限公司网站南宁seo产品优化服务
  • 福田欧曼服务站电话上海高端seo公司
  • 高端网站建设哪家好谷歌seo和百度seo
  • 前端写一个页面多少钱海口网站关键词优化
  • 浦东新区建设局官方网站东莞seo关键词
  • 在百度做橱柜网站进入百度一下官网
  • wordpress调用分类标签站长工具查询seo
  • 网站做全局搜索云南新闻最新消息今天
  • 公司网站推广方案长春seo代理
  • 网站地图怎么样做更利于收录手机百度搜索引擎入口
  • 中国建筑公司网站谷歌浏览器官方app下载
  • 厦门网站建设策划seo网站优化培训找哪些
  • 宝安区住房和建设局官方网站seo搜索引擎优化书籍
  • 省建设厅执业资格注册中心网站2023搜索最多的关键词
  • 本地wordpress上传搜索引擎营销优化策略有哪些
  • html手机网站模板培训心得体会800字
  • 合肥做网站公司哪家好经典的软文广告
  • 网站备案哪个部门北京推广
  • 澳环网站设计公司网站建设方案