Преглед на файлове

上传文件添加路径

zwp преди 5 месеца
родител
ревизия
3c272ac11d

+ 1 - 0
AIIM/Common/Network/aliOSS/OSSManager.h

@@ -49,6 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 -(void)stopUploadTanck:(NSString *)thrid;
 
+- (NSString *)fullUploadURLByAppendPath:(NSString *)path;
 
 @end
 

+ 26 - 3
AIIM/Common/Network/aliOSS/OSSManager.m

@@ -23,6 +23,8 @@
 
 @property (nonatomic, strong) OSSGetObjectRequest *normalDloadRequest;
 
+@property (nonatomic, strong) NSDateFormatter *formatter;
+@property (nonatomic, copy) NSString *month;
 @end
 
 
@@ -155,7 +157,7 @@
     NSLog(@"objectKey:%@",objectKey);
     _normalUploadRequest = [OSSPutObjectRequest new];
     _normalUploadRequest.bucketName = self.OSSInfo[@"bucket"];
-    _normalUploadRequest.objectKey = objectKey;
+    _normalUploadRequest.objectKey = [self formatObjectKeyWith:objectKey];
     _normalUploadRequest.uploadingFileURL = [NSURL fileURLWithPath:filePath];
     _normalUploadRequest.isAuthenticationRequired = YES;
     weakSelf(self);
@@ -249,7 +251,7 @@
     OSSResumableUploadRequest * resumableUpload = [OSSResumableUploadRequest new];
     resumableUpload.bucketName = self.OSSInfo[@"bucket"];
     // objectKey等同于objectName,表示断点上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg
-    resumableUpload.objectKey = objectKey;
+    resumableUpload.objectKey = [self formatObjectKeyWith:objectKey];
     resumableUpload.partSize = 1024 * 1024;
     resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
 //        NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
@@ -393,7 +395,7 @@
                 if([state isEqualToString:@"2"]){
                     NSString *localPath =extend[@"localurl"];
                     NSURL *loaclUrl = [NSURL URLWithString:localPath];
-                    NSString *url = [NSString stringWithFormat:@"http://oss.abtim-my.com/%@",loaclUrl.lastPathComponent];
+                    NSString *url = [self fullUploadURLByAppendPath:loaclUrl.lastPathComponent];
                     [mextend setObject:url forKey:@"url"];
                     [mextend setObject:[NSNumber numberWithInt:0] forKey:@"fileError"];
                     [mmsg setObject:mextend forKey:@"extend"];
@@ -456,6 +458,27 @@
     return false;
 }
 
+- (NSString *)fullUploadURLByAppendPath:(NSString *)path {
+    return [NSString stringWithFormat:@"http://oss.abtim-my.com/%@/%@", self.month, path];
+}
+
+- (NSDateFormatter *)formatter {
+    if (!_formatter) {
+        _formatter = [[NSDateFormatter alloc] init];
+        [_formatter setDateFormat:@"yyyy-MM"]; // 设置你想要的日期格式
+    }
+    return _formatter;
+}
 
+- (NSString *)month {
+    if (!_month) {
+        _month = [self.formatter stringFromDate:[NSDate date]];
+    }
+    return _month;
+}
+
+- (NSString *)formatObjectKeyWith:(NSString *)objectKey {
+    return [NSString stringWithFormat:@"%@/%@", self.month, objectKey];;
+}
 
 @end

+ 3 - 3
AIIM/Controller/chat/ChatController.m

@@ -1761,7 +1761,7 @@ static const CGFloat kQuoteViewHeight = 46.0f;
         filePath=[NSURL URLWithString:url]; //
     }
     else{
-        NSString *filestr = [NSString stringWithFormat:@"http://oss.abtim-my.com/%@",url];
+        NSString *filestr = [[OSSManager sharedManager] fullUploadURLByAppendPath:url];
         filePath=[NSURL URLWithString:filestr]; //
     }
     
@@ -1858,7 +1858,7 @@ static const CGFloat kQuoteViewHeight = 46.0f;
 -(void)uploadFileSucc:(NSString *)url localtime:(NSString *)localtime{
     
     if(![url containsString:@"http"]){
-        url = [NSString stringWithFormat:@"http://oss.abtim-my.com/%@",url];
+        url = [[OSSManager sharedManager] fullUploadURLByAppendPath:url];
     }
     NSURL *filePath = [NSURL URLWithString:url];
     
@@ -2067,7 +2067,7 @@ static const CGFloat kQuoteViewHeight = 46.0f;
         filePath=fileName;
     }
     else{
-        filePath = [NSString stringWithFormat:@"http://oss.abtim-my.com/%@",fileName];
+        filePath = [[OSSManager sharedManager] fullUploadURLByAppendPath:fileName];
     }
     NSString *content=@"【语音】";
     NSString *messageType=[NSString stringWithFormat:@"%@",MessageType_voice];

+ 7 - 9
AIIM/Controller/chat/chetCell/ChatMessageModel.m

@@ -75,8 +75,8 @@
     
     
     self.url = extend[@"url"] ?: @"";
-    NSCharacterSet *allowedCharacters = [NSCharacterSet URLQueryAllowedCharacterSet];
-    self.url = [self.url stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
+//    NSCharacterSet *allowedCharacters = [NSCharacterSet URLQueryAllowedCharacterSet];
+//    self.url = [self.url stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
     self.localurl = extend[@"localurl"] ?: @"";
     
     self.quoteMessage = ![extend jk_hasKey:@"quoteMessage"] ?NULL: [ChatMessageModel modelWithDictionary:extend[@"quoteMessage"]];
@@ -393,13 +393,12 @@
 
 //下载视频文件
 -(void)downloadFileIfNeed:(void(^)(NSInteger persent))loading{
-    NSString *localFileurl = [self.localurl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];
-    if (self.localurl.length != 0 && [[NSFileManager defaultManager] fileExistsAtPath:localFileurl]){
+    if ([[NSFileManager defaultManager] fileExistsAtPath:self.localurl]){
         self.customFileSize = [self getFileSize];
         if (loading) {
             loading(100);
         }
-        NSLog(@"downloadFileIfNeed 0: %@", localFileurl);
+        NSLog(@"downloadFileIfNeed 0: %@", self.localurl);
         return;
     }
     
@@ -510,11 +509,10 @@
 }
 
 - (NSString *)checkHasLocalPath {
-    NSString *localFileurl = [self.localurl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];
-    if (self.localurl.length != 0 && [[NSFileManager defaultManager] fileExistsAtPath:localFileurl]){
+    if ([[NSFileManager defaultManager] fileExistsAtPath:self.localurl]){
         self.customFileSize = [self getFileSize];
-        NSLog(@"checkHasLocalPath 0: %@", localFileurl);
-        return localFileurl;
+        NSLog(@"checkHasLocalPath 0: %@", self.localurl);
+        return self.localurl;
     }
     
     NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];

+ 0 - 1
AIIM/Controller/chat/chetCell/chatCellView.m

@@ -1552,7 +1552,6 @@ static const CGFloat kMediaCornerRadius = 4.0f;
                 sizeLabel.text = [NSString stringWithFormat:@"%ld",(long)persent];
                 if(persent>=100){
                     sizeLabel.text = weakself.messageModel.customFileSize;
-                    NSLog(@"setupFileContent:下载完成:%@",weakself.messageModel.localurl);
                     [FilePreviewer.shared previewFileWithLocalPath:weakself.messageModel.localurl
                                                          remoteURL:getURL(weakself.messageModel.url)
                                                 fromViewController:weakself.parentViewController];