>
>
com.aliyun.ossgroupid
>
>
aliyun-sdk-ossartifactid
>
>
3.11.1version
>
dependency
>
>
>
joda-timegroupid
>
>
joda-timeartifactid
>
>
2.10.8version
>
dependency
>
#阿里雲 oss
aliyun.oss.file.endpoint=你的 oss-cn-shenzhen.aliyuncs.com
aliyun.oss.file.keyid=你的 access-key
aliyun.oss.file.keysecret=你的 secret-key:
aliyun.oss.file.bucketname=你的桶名
package com.jili20.util;
import org.springframework.beans.factory.initializingbean;
import org.springframework.beans.factory.annotation.value;
import org.springframework.stereotype.component;
/** * @author bing @create 2020/11/30-4:10 下午
*/@component
public
class
ossconstantutils
implements
initializingbean")
private string endpoint;
@value
("$"
)private string keyid;
@value
("$"
)private string keysecret;
@value
("$"
)private string bucketname;
//定義公開靜態常量
public
static string end_poind;
public
static string access_key_id;
public
static string access_key_secret;
public
static string bucket_name;
@override
public
void
afterpropertiesset()
throws exception
}
package com.jili20.controller;
。。。。。。
/** * @author bing @create 2020/11/30-11:02 下午
*/@controller
public
class
usercontroller
implements
communityconstant
// 上傳頭像到阿里雲oss
@loginrequired
// 自定義註解,登入才能訪問
("/user/upload"
)public string uploadheader
(multipartfile headerimage, model model, redirectattributes attr)
// 工具類獲取值
string endpoint = ossconstantutils.end_poind;
string accesskeyid = ossconstantutils.access_key_id;
string accesskeysecret = ossconstantutils.access_key_secret;
string bucketname = ossconstantutils.bucket_name;
tryreturn
"redirect:/user/setting";}
catch
(ioexception e)
}}
class
="mt-5"
method
="post"
enctype
="multipart/form-data"
th:action
="@"
>
class
="form-group row mt-4"
>
for=
"head-image"
class
="col-sm-2 col-form-label text-right"
>
選擇頭像:label
>
class
="col-sm-10"
>
class
="custom-file"
>
type
="file"
th:class
="|custom-file-input $|"
id="head-image"
name
="headerimage"
lang
="es"
required="
">
class
="custom-file-label"
for="head-image"
data-browse
="檔案"
>
選擇一張label
>
class
="invalid-feedback"
th:text
="$"
>
該賬號不存在!
div>
div>
div>
div>
class
="form-group row mt-4"
>
class
="col-sm-2"
>
div>
class
="col-sm-10 text-center"
>
type
="submit"
class
="btn btn-info text-white form-control"
>
立即上傳button
>
div>
div>
form
>
Springboot 上傳頭像
頭像上傳路徑,若不存在,會根據該路徑建立指定路徑資料夾 upload path d upload headimgs 建立類 fileutils 並讀取配置檔案中的值 component configurationproperties prefix upload data public class f...
Retrofit上傳頭像
retrofit retrofit new retrofit.builder baseurl addconverte ctory gsonconverte ctory.create gson工廠類 build githubapi api retrofit.create githubapi.class...
JavaWeb上傳頭像
最近工作中遇到需要維護個人資訊,包括頭像資訊,再次記錄,方便以後使用 前端 新增附件 js 上傳檔案 function openselectfile uploadfile fileupload autoupload true,add function e,data var size data.fil...