File Repository


File Repository 는 HSP 에서 기본으로 제공하는 API로 별도의 설정 없이 사용 가능하다.

File Repository 는 HSP 에 미리 선언 해둔 특정 위치에 파일을 저장 / 삭제 / 검색의 기능을 가지고 있으며 해당 클래스는 Optional 한 기능이므로 사용자가 별도로 개발하여 사용해도 무방하다. 


save

save 는 로컬내 파일 이나 외부 (http link) 의 데이터를 HSP 에 지정된 경로에 저장할 때 사용할 수 있으며, 만약 저장하려는 파일이 zip 파일일때는 압축 해제까지 한번에 처리할 수 있으며, 올바르게 파일을 저장하였다면 HMPRepositoryData 클래스 형태로 파일에 대한 정보를 반환 하게 되며 HMPRepositoryData 클래스에 세부 내용은 하단의 표를 참고 한다. 

HMPRepositoryData Class

@interface HMPRepositoryData : NSObject

@property (nonatomic, retain) NSString *bizAppId;
@property (nonatomic, retain) NSString *fileName;
@property (nonatomic, retain) NSString *filePath;
@property (nonatomic, assign) NSInteger fileSize;
@property (nonatomic, retain) NSString *saveDate;

+ (id)dataWithBizAppId:(NSString *)bizAppId fileName:(NSString *)fileName filePath:(NSString *)filePath fileSize:(NSInteger)fileSize saveDate:(NSString *)saveDate;

@end

 

HMPRepositoryData

필드설명
bizAppId앱 아이디
fileName파일 이름
filePath파일 경로
fileSize파일 사이즈
saveData저장 시간
  

 

Example

///////////////
// 3.10.18 이상
///////////////
let deviceAPI = DAPFileRepository()
let infoParam = DAPFileRepositorySaveParam()
guard let bizAppId = info["bizAppId"] as? String,
   let originalURL = info["originalURL"] as? String,
   let fileName = info["fileName"] as? String,
   let isCompress = info["isCompress"]  as? NSNumber else {
       return
}

infoParam.bizAppId = bizAppId
infoParam.originalURL = originalURL
infoParam.fileName = fileName
infoParam.isCompress = isCompress.boolValue
deviceAPI.execute(with: infoParam, completion: { (dict) in
   guard let resultDict = dict as NSDictionary? else {
       return
    }
   
}, failure: { (resultError) in
   guard let error = resultError else {
       return
    }
   
})


///////////////
// 3.10.18 이하
///////////////
let deviceAPI = DAPFileRepository()
guard let bizAppId = info["bizAppId"],
   let originalURL = info["originalURL"],
   let fileName = info["fileName"],
   let isCompress = info["isCompress"] else {
       return
}

let params = [bizAppId, originalURL, fileName, isCompress]
deviceAPI.execute(withActionName: "save", params: params, completion: { (dict) in
   guard let resultDict = dict as NSDictionary? else {
       return
    }
   
}, failure: { (resultError) in
   guard let error = resultError else {
       return
    }
   
})

///////////////
// 3.10.18 이상
///////////////
DAPDeviceAPI *deviceAPI = [DAPFileRepository new];
DAPFileRepositorySaveParam *infoParam = [DAPFileRepositorySaveParam new];
infoParam.bizAppId = [info objectForKey:@"bizAppId"];
infoParam.originalURL = [info objectForKey:@"originalURL"];
infoParam.fileName = [info objectForKey:@"fileName"];
NSNumber *isComplress = [info objectForKey:@"isCompress"];
infoParam.isCompress = [isComplress boolValue];

[deviceAPI executeWithParam:infoParam completion:^(NSDictionary *resultDict) {
   NSString *path = [[resultDict objectForKey:kDeviceResult] objectForKey:@"filePath"];
} failure:^(NSError *error) {
    [self showErrorDlgWithError:error];
}];

///////////////
// 3.10.18 이하
///////////////
NSArray *params = [NSArray arrayWithObjects:@"main", @"http://www.hsnc.co.kr/kr/mobile/mod/images/com/logo.png", @"logo.png", NO, nil];
[deviceAPI executeWithActionName:@"save" params:params completion:^(NSDictionary *resultDict) {
    NSLog(@"%s %d\nresultDict %@", __PRETTY_FUNCTION__, __LINE__, resultDict);
} failure:^(NSError *error) {
    NSLog(@"%s %d\nerror %@", __PRETTY_FUNCTION__, __LINE__, error);
}];

 

Parameters

파라미터설명
첫번째 인자비즈 앱 아이디
두번째 인자원본URL
세번째 인자파일이름
네번째 인자

파일압축여부(zip), 압축파일이면 다운받은 후 압축을 해제
"true" : 압축파일
"false" : 압축파일이 아님
이 옵션은  압축된경우에만 기술 (현재 미지원)

  

find

find 는 지정 위치에 파일 이름을 검색해 관련 파일 정보를 NSArray 형태로 전달 받는다. 

Example

///////////////
// 3.10.18 이상
///////////////
let deviceAPI = DAPFileRepository()
let infoParam = DAPFileRepositoryFindParam()
guard let bizAppId = info["bizAppId"] as? String,
   let fileName = info["fileName"] as? String else {
       return
}

infoParam.bizAppId = bizAppId
infoParam.fileName = fileName
deviceAPI.execute(with: infoParam, completion: { (dict) in
   guard let resultDict = dict as NSDictionary? else {
       return
    }
   
}, failure: { (resultError) in
   guard let error = resultError else {
       return
    }
   
})


///////////////
// 3.10.18 이하
///////////////
let deviceAPI = DAPFileRepository()
guard let bizAppId = info["bizAppId"],
   let fileName = info["fileName"] else {
       return
}

let params = [bizAppId, fileName]
deviceAPI.execute(withActionName: "find", params: params, completion: { (dict) in
   guard let resultDict = dict as NSDictionary? else {
       return
    }
   
}, failure: { (resultError) in
   guard let error = resultError else {
       return
    }
   
})

///////////////
// 3.10.18 이상
///////////////
DAPDeviceAPI *deviceAPI = [DAPFileRepository new];
DAPFileRepositoryFindParam *infoParam = [DAPFileRepositoryFindParam new];
infoParam.bizAppId = @"bizAppId";
infoParam.fileName = @"fileName";
[deviceAPI executeWithParam:infoParam completion:^(NSDictionary *resultDict) {
    ResultData *resultData = [ResultData resultDataWithType:@"fileRepositoryResultDlg" resultObject:[resultDict objectForKey:kDeviceResult]];
    [self showSuccessDlgWithResultData:resultData];
} failure:^(NSError *error) {
    [self showErrorDlgWithError:error];
}];

///////////////
// 3.10.18 이하
///////////////
DAPDeviceAPI *deviceAPI = [DAPFileRepository new];

NSArray *params = [NSArray arrayWithObjects:@"main", @"logo.png", nil];
[deviceAPI executeWithActionName:@"find" params:params completion:^(NSDictionary *resultDict) {
    NSLog(@"%s %d\nresultDict %@", __PRETTY_FUNCTION__, __LINE__, resultDict);
} failure:^(NSError *error) {
    NSLog(@"%s %d\nerror %@", __PRETTY_FUNCTION__, __LINE__, error);
}];

 

Parameters

파라미터설명
첫번째 인자비즈 앱 아이디
두번째 인자파일명
  

remove

파일의 대한 경로를 전달하여 해당 파일을 삭제 요청 한다. 

Example

///////////////
// 3.10.18 이상
///////////////
let deviceAPI = DAPFileRepository()
guard let filePath = info["filePath"] as? String else {
   return
}

let infoParam = DAPFileRepositoryRemoveParam()
infoParam.localFilePath = filePath
deviceAPI.execute(with: infoParam, completion: { (dict) in
   guard let _ = dict as NSDictionary? else {
       return
    }
   
}, failure: { (resultError) in
   guard let error = resultError else {
       return
    }
   
})


///////////////
// 3.10.18 이하
///////////////
let deviceAPI = DAPFileRepository()
guard let filePath = info["filePath"] else {
   return
}

let params = [filePath]
deviceAPI.execute(withActionName: "remove", params: params, completion: { (dict) in
   if completion == nil {
       return
    }
   
}, failure: { (resultError) in
   guard let error = resultError else {
       return
    }
   
})

///////////////
// 3.10.18 이상
///////////////
DAPDeviceAPI *deviceAPI = [DAPFileRepository new];
DAPFileRepositoryRemoveParam *infoParam = [DAPFileRepositoryRemoveParam new];
infoParam.localFilePath = @"file://documents/test.png";
[deviceAPI executeWithParam:infoParam completion:^(NSDictionary *resultDict) {
   if (completion == nil) {
       return;
    }
   
    completion(resultDict);
} failure:^(NSError *error) {
    [self showErrorDlgWithError:error];
}];


///////////////
// 3.10.18 이하
///////////////
DAPDeviceAPI *deviceAPI = [DAPFileRepository new];

NSArray *params = [NSArray arrayWithObjects:@"file://documents/test.png", nil];
[deviceAPI executeWithActionName:@"remove" params:params completion:^(NSDictionary *resultDict) {
    NSLog(@"%s %d\nresultDict %@", __PRETTY_FUNCTION__, __LINE__, resultDict);
} failure:^(NSError *error) {
    NSLog(@"%s %d\nerror %@", __PRETTY_FUNCTION__, __LINE__, error);
}];

 

Parameters

파라미터설명
첫번째 인자로컬 파일 경로