更换腾讯cos上传
This commit is contained in:
@@ -214,20 +214,35 @@
|
||||
}
|
||||
NSMutableArray *files = [[NSMutableArray alloc] initWithObjects:fileData, nil];
|
||||
|
||||
NSString *fileBasePath = IMG_FILE_BASE_PATH;// 默认图片上传
|
||||
NSString *fileName = [NSString stringWithFormat:@"%@%@/%@.%@",fileBasePath,[[QXOSSManager sharedInstance] currentDate],[NSUUID UUID].UUIDString,contentType];
|
||||
NSMutableArray *fileNames = [[NSMutableArray alloc] initWithObjects:fileName, nil];
|
||||
// NSString *fileBasePath = IMG_FILE_BASE_PATH;// 默认图片上传
|
||||
// NSString *fileName = [NSString stringWithFormat:@"%@%@/%@.%@",fileBasePath,[[QXOSSManager sharedInstance] currentDate],[NSUUID UUID].UUIDString,contentType];
|
||||
// NSMutableArray *fileNames = [[NSMutableArray alloc] initWithObjects:fileName, nil];
|
||||
// __weak typeof(self)weakSelf = self;
|
||||
// showLoadingInView(self.view);
|
||||
// [[QXOSSManager sharedInstance] uploadFile:files withObjectKey:fileNames isAsync:YES complete:^(NSArray<NSString *> *names, UploadImageState state) {
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// hideLoadingInView(weakSelf.view);
|
||||
// });
|
||||
// if (state == UploadImageSuccess) {
|
||||
// NSString *fileName = [names lastObject];
|
||||
// NSString *fileUrl =[NSString stringWithFormat:@"https://%@.%@/%@",OSS_BUCKET_NAME,OSSEndPoint,fileName];
|
||||
// weakSelf.avartar = fileUrl;
|
||||
// [weakSelf.selectedBtn sd_setImageWithURL:[NSURL URLWithString:fileUrl] forState:(UIControlStateNormal)];
|
||||
// }else{
|
||||
// showToastInView(QXText(@"文件上传失败,请重新尝试"), weakSelf.view);
|
||||
// }
|
||||
// }];
|
||||
|
||||
__weak typeof(self)weakSelf = self;
|
||||
showLoadingInView(self.view);
|
||||
[[QXOSSManager sharedInstance] uploadFile:files withObjectKey:fileNames isAsync:YES complete:^(NSArray<NSString *> *names, UploadImageState state) {
|
||||
NSString *fileName = [NSString stringWithFormat:@"%@.%@",[[QXCOSUploadManager shareManager] currentDate],contentType];
|
||||
[[QXCOSUploadManager shareManager] uploadFile:files withObjectKey:@[fileName] isAsync:YES complete:^(NSArray<NSString *> * _Nonnull names, QXCOSUploadImageState state) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
hideLoadingInView(weakSelf.view);
|
||||
});
|
||||
if (state == UploadImageSuccess) {
|
||||
NSString *fileName = [names lastObject];
|
||||
NSString *fileUrl =[NSString stringWithFormat:@"https://%@.%@/%@",OSS_BUCKET_NAME,OSSEndPoint,fileName];
|
||||
weakSelf.avartar = fileUrl;
|
||||
[weakSelf.selectedBtn sd_setImageWithURL:[NSURL URLWithString:fileUrl] forState:(UIControlStateNormal)];
|
||||
if (state == QXCOSUploadImageSuccess) {
|
||||
weakSelf.avartar = names.firstObject;
|
||||
[weakSelf.selectedBtn sd_setImageWithURL:[NSURL URLWithString:weakSelf.avartar] forState:(UIControlStateNormal)];
|
||||
}else{
|
||||
showToastInView(QXText(@"文件上传失败,请重新尝试"), weakSelf.view);
|
||||
}
|
||||
|
||||
@@ -386,19 +386,38 @@
|
||||
[self presentViewController:imagePickerVc animated:YES completion:nil];
|
||||
}
|
||||
- (void)OSSUploadPhoto{
|
||||
// __weak typeof(self)weakSelf = self;
|
||||
// showLoadingInView(self.view);
|
||||
// [[QXOSSManager sharedInstance] activityUploadFile:self.uploadArray withObjectKey:self.keyArray isAsync:YES complete:^(NSArray<NSString *> *names, UploadImageState state) {
|
||||
// dispatch_async_and_wait(dispatch_get_main_queue(), ^{
|
||||
// [weakSelf.urlArray removeAllObjects];
|
||||
// hideLoadingInView(weakSelf.view);
|
||||
// if (state == UploadImageSuccess) {
|
||||
// showToast(QXText(@"上传成功"));
|
||||
// for (int i = 0; i < names.count; i++) {
|
||||
// NSString *name = names[i];
|
||||
// NSString *fileUrl =[NSString stringWithFormat:@"https://%@.%@/%@",OSS_BUCKET_NAME,OSSEndPoint,name];
|
||||
// [weakSelf.urlArray addObject:fileUrl];
|
||||
// }
|
||||
// [weakSelf uploadImages];
|
||||
// }else{
|
||||
// showToast(QXText(@"上传失败"));
|
||||
// }
|
||||
// });
|
||||
// }];
|
||||
__weak typeof(self)weakSelf = self;
|
||||
showLoadingInView(self.view);
|
||||
[[QXOSSManager sharedInstance] activityUploadFile:self.uploadArray withObjectKey:self.keyArray isAsync:YES complete:^(NSArray<NSString *> *names, UploadImageState state) {
|
||||
dispatch_async_and_wait(dispatch_get_main_queue(), ^{
|
||||
[weakSelf.urlArray removeAllObjects];
|
||||
[[QXCOSUploadManager shareManager] activityUploadFile:self.uploadArray withObjectKey:self.keyArray isAsync:YES complete:^(NSArray<NSString *> * _Nonnull names, QXCOSUploadImageState state) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
hideLoadingInView(weakSelf.view);
|
||||
if (state == UploadImageSuccess) {
|
||||
showToast(QXText(@"上传成功"));
|
||||
[weakSelf.urlArray removeAllObjects];
|
||||
if (state == QXCOSUploadImageSuccess) {
|
||||
for (int i = 0; i < names.count; i++) {
|
||||
NSString *name = names[i];
|
||||
NSString *fileUrl =[NSString stringWithFormat:@"https://%@.%@/%@",OSS_BUCKET_NAME,OSSEndPoint,name];
|
||||
[weakSelf.urlArray addObject:fileUrl];
|
||||
// NSString *fileUrl =[NSString stringWithFormat:@"https://%@.%@/%@",OSS_BUCKET_NAME,OSSEndPoint,name];
|
||||
[weakSelf.urlArray addObject:name];
|
||||
}
|
||||
showToast(QXText(@"上传成功"));
|
||||
[weakSelf uploadImages];
|
||||
}else{
|
||||
showToast(QXText(@"上传失败"));
|
||||
@@ -423,8 +442,10 @@
|
||||
}];
|
||||
}
|
||||
- (NSString *)imagePathWithKey:(NSString *)keyPath {
|
||||
NSString *fileBasePath = IMG_FILE_BASE_PATH;
|
||||
return [NSString stringWithFormat:@"%@%@/%@.%@",fileBasePath,[[QXOSSManager sharedInstance] currentDate],[NSUUID UUID].UUIDString,keyPath];
|
||||
// NSString *fileBasePath = IMG_FILE_BASE_PATH;
|
||||
// return [NSString stringWithFormat:@"%@%@/%@.%@",fileBasePath,[[QXOSSManager sharedInstance] currentDate],[NSUUID UUID].UUIDString,keyPath];
|
||||
NSString *fileName = [NSString stringWithFormat:@"%@.%@",[[QXCOSUploadManager shareManager] currentDate],keyPath];
|
||||
return fileName;
|
||||
}
|
||||
|
||||
-(NSMutableArray *)valueArray{
|
||||
|
||||
Reference in New Issue
Block a user