Browse Source

Upload user profile picture

pull/217/head
cKey 5 years ago
parent
commit
0b52236557
  1. 2
      aspnet-core/LINGYUN.MicroService.All.sln
  2. 9
      aspnet-core/LINGYUN.MicroService.Platform.sln
  3. 2
      aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Aliyun/LINGYUN/Abp/OssManagement/Aliyun/AliyunOssContainer.cs
  4. 1
      aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/CreateOssObjectInput.cs
  5. 5
      aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/OssObjectAppService.cs
  6. 1
      aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain/LINGYUN/Abp/OssManagement/CreateOssObjectRequest.cs
  7. 5
      aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/LINGYUN/Abp/OssManagement/FileSystem/FileSystemOssContainer.cs
  8. 10
      aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/StaticFilesController.cs
  9. 1
      vueJs/src/api/profile.ts
  10. 2
      vueJs/src/layout/components/Navbar/index.vue
  11. 28
      vueJs/src/views/profile/components/MyProfile.vue

2
aspnet-core/LINGYUN.MicroService.All.sln

@ -179,7 +179,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Identity.HttpAp
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "oss-management", "oss-management", "{B05CB08F-C088-4D6D-97EE-A94A5D1AE4A6}"
ProjectSection(SolutionItems) = preProject
modules\cloud-aliyun\LINGYUN.Abp.Aliyun\README.md = modules\cloud-aliyun\LINGYUN.Abp.Aliyun\README.md
modules\oss-management\README.md = modules\oss-management\README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.OssManagement.Application", "modules\oss-management\LINGYUN.Abp.OssManagement.Application\LINGYUN.Abp.OssManagement.Application.csproj", "{F3D50E3E-34D2-48C1-AB0D-ADCF92DC07D0}"

9
aspnet-core/LINGYUN.MicroService.Platform.sln

@ -24,6 +24,9 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "platform", "platform", "{4096EC6A-EEAD-4E5B-B087-393D7A4E5874}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "oss-management", "oss-management", "{C7D0EB39-3418-4A7C-AD94-FAB76F023E88}"
ProjectSection(SolutionItems) = preProject
modules\oss-management\README.md = modules\oss-management\README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.OssManagement.Domain.Shared", "modules\oss-management\LINGYUN.Abp.OssManagement.Domain.Shared\LINGYUN.Abp.OssManagement.Domain.Shared.csproj", "{4D3C1EBD-1A4A-4300-A889-72DA0E082BAE}"
EndProject
@ -49,7 +52,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Platform.EntityFram
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Platform.Domain.Tests", "tests\LINGYUN.Platform.Domain.Tests\LINGYUN.Platform.Domain.Tests.csproj", "{C60A06F2-0F4C-483F-BE2B-B103F0D726CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.OssManagement.Aliyun", "modules\oss-management\LINGYUN.Abp.OssManagement.Aliyun\LINGYUN.Abp.OssManagement.Aliyun.csproj", "{104EDC09-0CEA-4AB0-BFF5-B009D4679419}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.OssManagement.Aliyun", "modules\oss-management\LINGYUN.Abp.OssManagement.Aliyun\LINGYUN.Abp.OssManagement.Aliyun.csproj", "{104EDC09-0CEA-4AB0-BFF5-B009D4679419}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{265D5E44-682B-49BC-984A-BDD8CA45E60E}"
EndProject
@ -57,7 +60,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Aliyun", "modul
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BlobStoring.Aliyun", "modules\common\LINGYUN.Abp.BlobStoring.Aliyun\LINGYUN.Abp.BlobStoring.Aliyun.csproj", "{95E0D070-ACFB-40DF-A4EC-FC75EA5AF6B0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.OssManagement.FileSystem", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem\LINGYUN.Abp.OssManagement.FileSystem.csproj", "{B5569DCD-445E-445B-87E7-D8D4E03F0F76}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.OssManagement.FileSystem", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem\LINGYUN.Abp.OssManagement.FileSystem.csproj", "{B5569DCD-445E-445B-87E7-D8D4E03F0F76}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.OssManagement.FileSystem.ImageSharp", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem.ImageSharp\LINGYUN.Abp.OssManagement.FileSystem.ImageSharp.csproj", "{1AA232B1-5999-43AE-A5C8-7973AFCC8BD1}"
EndProject
@ -69,7 +72,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "setting-management", "setti
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.SettingManagement.Application.Contracts", "modules\settings\LINGYUN.Abp.SettingManagement.Application.Contracts\LINGYUN.Abp.SettingManagement.Application.Contracts.csproj", "{D1D288D1-3178-439F-8EFD-E29D6F66E673}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.OssManagement.SettingManagement", "modules\oss-management\LINGYUN.Abp.OssManagement.SettingManagement\LINGYUN.Abp.OssManagement.SettingManagement.csproj", "{07D1B07A-3C95-40A8-AA53-619EC067FD45}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.OssManagement.SettingManagement", "modules\oss-management\LINGYUN.Abp.OssManagement.SettingManagement\LINGYUN.Abp.OssManagement.SettingManagement.csproj", "{07D1B07A-3C95-40A8-AA53-619EC067FD45}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

2
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Aliyun/LINGYUN/Abp/OssManagement/Aliyun/AliyunOssContainer.cs

@ -67,7 +67,7 @@ namespace LINGYUN.Abp.OssManagement.Aliyun
? request.Object
: objectPath + request.Object;
if (ObjectExists(ossClient, request.Bucket, objectName))
if (!request.Overwrite && ObjectExists(ossClient, request.Bucket, objectName))
{
throw new BusinessException(code: OssManagementErrorCodes.ObjectAlreadyExists);
}

1
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/CreateOssObjectInput.cs

@ -10,6 +10,7 @@ namespace LINGYUN.Abp.OssManagement
public string Bucket { get; set; }
public string Path { get; set; }
public string Object { get; set; }
public bool Overwrite { get; set; }
[DisableAuditing]
[DisableValidation]

5
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/OssObjectAppService.cs

@ -65,7 +65,10 @@ namespace LINGYUN.Abp.OssManagement
input.Object,
input.Content,
input.Path,
input.ExpirationTime);
input.ExpirationTime)
{
Overwrite = input.Overwrite
};
var ossObject = await oss.CreateObjectAsync(createOssObjectRequest);
return ObjectMapper.Map<OssObject, OssObjectDto>(ossObject);

1
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain/LINGYUN/Abp/OssManagement/CreateOssObjectRequest.cs

@ -10,6 +10,7 @@ namespace LINGYUN.Abp.OssManagement
public string Bucket { get; }
public string Path { get; }
public string Object { get; }
public bool Overwrite { get; set; }
public Stream Content { get; private set; }
public TimeSpan? ExpirationTime { get; }
public CreateOssObjectRequest(

5
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/LINGYUN/Abp/OssManagement/FileSystem/FileSystemOssContainer.cs

@ -106,7 +106,8 @@ namespace LINGYUN.Abp.OssManagement.FileSystem
{
ThrowOfPathHasTooLong(filePath);
if (File.Exists(filePath))
FileMode fileMode = request.Overwrite ? FileMode.Create : FileMode.CreateNew;
if (!request.Overwrite && File.Exists(filePath))
{
throw new BusinessException(code: OssManagementErrorCodes.ObjectAlreadyExists);
// throw new OssObjectAlreadyExistsException($"Can't not put object {objectName} in container {request.Bucket}, Because a file with the same name already exists in the directory!");
@ -114,7 +115,7 @@ namespace LINGYUN.Abp.OssManagement.FileSystem
DirectoryHelper.CreateIfNotExists(Path.GetDirectoryName(filePath));
using (var fileStream = File.Open(filePath, FileMode.CreateNew, FileAccess.Write))
using (var fileStream = File.Open(filePath, fileMode, FileAccess.Write))
{
await request.Content.CopyToAsync(fileStream);

10
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/StaticFilesController.cs

@ -32,9 +32,10 @@ namespace LINGYUN.Abp.OssManagement
[HttpPost]
[Route("{bucket}")]
[Route("{bucket}/{path}")]
[Route("{bucket}/p/{path}")]
[Route("{bucket}/p/{path}/{name}")]
[Authorize(AbpOssManagementPermissions.OssObject.Create)]
public virtual async Task<OssObjectDto> UploadAsync(string bucket, string path, [FromForm] IFormFile file)
public virtual async Task<OssObjectDto> UploadAsync(string bucket, string path, string name, [FromForm] IFormFile file)
{
if (file == null || file.Length <= 0)
{
@ -45,8 +46,9 @@ namespace LINGYUN.Abp.OssManagement
{
Bucket = HttpUtility.UrlDecode(bucket),
Path = HttpUtility.UrlDecode(path),
Object = file.FileName,
Content = file.OpenReadStream()
Object = name ?? file.FileName,
Content = file.OpenReadStream(),
Overwrite = true
};
return await _ossObjectAppService.CreateAsync(createOssObjectInput);

1
vueJs/src/api/profile.ts

@ -48,6 +48,7 @@ export class MyProfile extends MyProfileBase {
}
export class UpdateMyProfile extends MyProfileBase {
extraProperties?: {[key: string]: any }
}
export class ChangePassword {

2
vueJs/src/layout/components/Navbar/index.vue

@ -41,7 +41,7 @@
{{ $t('AbpAccount.PersonalInfo') }}
</el-dropdown-item>
</router-link>
<router-link to="/profile-setting/">
<router-link to="/profile/setting">
<el-dropdown-item>
<svg-icon name="setting" />
{{ $t('AbpAccount.PersonalSettings') }}

28
vueJs/src/views/profile/components/MyProfile.vue

@ -47,7 +47,7 @@
</el-button>
<avatar-upload
v-model="showImageUpload"
field="avatar"
field="file"
:width="300"
:height="300"
:params="params"
@ -89,7 +89,7 @@
<script lang="ts">
import MyProfileService, { MyProfile, UpdateMyProfile } from '@/api/profile'
import { FileUploadUrl } from '@/api/filemanagement'
import OssManagerApi from '@/api/oss-manager'
import { Component, Vue } from 'vue-property-decorator'
import { UserModule } from '@/store/modules/user'
import AvatarUpload from '@/components/AvatarUpload/index.vue'
@ -108,13 +108,14 @@ export default class extends Vue {
private showImageUpload = false
private headers: any = {}
private params: any = {}
private uploadUrl = FileUploadUrl
private uploadUrl = ''
get myAvatar() {
if (this.myProfile.extraProperties) {
const avatar = this.myProfile.extraProperties.avatar
const avatar = this.myProfile.extraProperties.AvatarUrl
if (avatar) {
return avatar
//
return avatar + '/w_300,h_300'
}
}
return ''
@ -122,7 +123,7 @@ export default class extends Vue {
set myAvatar(avatar: string) {
if (this.myProfile.extraProperties) {
this.myProfile.extraProperties.avatar = avatar
this.myProfile.extraProperties.AvatarUrl = avatar
}
}
@ -137,13 +138,8 @@ export default class extends Vue {
this.headers.Authorization = UserModule.token
}
private handleSrcFileSet(fileName: string, fileType: any, fileSize: any) {
this.params.FileName = fileName
this.params.ChunkSize = fileSize
this.params.CurrentChunkSize = fileSize
this.params.ChunkNumber = 1
this.params.TotalChunks = 1
this.params.TotalSize = fileSize
private handleSrcFileSet(fileName: string) {
this.uploadUrl = OssManagerApi.generateOssUrl('user-account', fileName, UserModule.userName + '/', '/api')
}
private handleUploadFail(status: any, field: any) {
@ -151,10 +147,9 @@ export default class extends Vue {
console.log(field)
}
private onCropUploadSuccess(jsonData: any, field: string) {
private onCropUploadSuccess() {
this.showImageUpload = false
console.log(jsonData)
console.log(field)
this.myAvatar = this.uploadUrl
}
private handleUpdateMyProfile() {
@ -169,6 +164,7 @@ export default class extends Vue {
this.myProfile.surname,
this.myProfile.phoneNumber
)
updateProfile.extraProperties = this.myProfile.extraProperties
MyProfileService.updateMyProfile(updateProfile).then(profile => {
this.myProfile = profile
this.$message.success(this.$t('AbpAccount.PersonalSettingsSaved').toString())

Loading…
Cancel
Save