Professional Documents
Culture Documents
if (this.CheckFileSize(files[0].size, this.model.value)) {
this.swalPopUpMsg('V;File size must be less or equal to ' + this.model.value + ' MB');
$('#datatablesssss').DataTable().ajax.reload(); //ganti dengan nama datatable jika ini
di list
} else {
if (event.target.files && event.target.files[0]) {
const reader = new FileReader();
// tslint:disable-next-line:no-shadowed-variable
reader.onload = (event) => {
reader.onload = this.handleFile.bind(this);
reader.readAsBinaryString(file);
}
}
this.tempFile = files[0].name;
this.tampDocumentCode = code;
}
}
//#endregion button select image
this.tamps.push({
p_header: 'PUBLIC_SERVICE_DOCUMENT', //ganti dengan nama menu
p_module:'IFINPBS', //ganti dengan nama module
p_child: this.param,
p_id: this.tampDocumentCode,
p_file_path: this.tampDocumentCode,
p_file_name: this.tempFile,
p_base64: this.base64textString
});
- base.component.ts
//#region CheckFileSize
CheckFileSize(fileSize: any, maxFileSize: any) {
if (fileSize / 1024 / 1024 > maxFileSize) {
return true;
} else {
return false;
}
}
//#endregion
Dalservice.ts
PriviewFile(data: any, controller: String, route: String):
Observable<any> {
const result = JSON.stringify(data);
const url = `${this._urlAddress + controller + '/' + route}`;
return this._http.post<any[]>(url, result, this.httpOptions).pipe(
tap(_ => console.log(`priview image=${data[0].p_file_name}`)),
catchError(this.handleError)
);
}
API
- appsettings.json
"DocumentSetting": {
"docPrintSetting": "0" //document bisa di print dalam bentuk fisik maupun langsung ke database dalam bentuk blob (fisik: 0, blob:1)
},
"UrlApiCall": {
"docPathIfinsys": "",
"docPathIfinOpl": "\\Files",
"ifindocUploadUrl": "http://localhost:34232/api/DocumentMain/Uploadfile",
"ifindocDeleteUrl": "http://localhost:34232/api/DocumentMain/Deletefile"
},
- IfinancingController
Declare secretKey :
_docPrintSetting = configuration.GetValue<string>("DocumentSetting:docPrintSetting");
TamabahFunction PostUploadImage :
protected async Task<object> PostUploadImage([FromBody] dynamic data, string SpName, IHttpClientFactory _httpClientFactory)
{
string Username = decodeHeader(Request.Headers["UserID"]);//Request.Headers["UserID"]; // get id user
string IPAddress = Request.Headers["IPAddress"]; // decodeHeader(Request.Headers["IPAddress"]); // get IPAddress
GeneralDAL _dal = null;
Hashtable _htParameters = null;
string filePath = String.Empty;
string filePathCode = String.Empty;
string fileName = String.Empty;
string uploadResult = String.Empty;
string uploadFailedMessage = String.Empty;
object result = null;
var res = (string)null;
try
{
_dal = new GeneralDAL(_connectionString);
_htParameters = new Hashtable();
if (response.IsSuccessStatusCode)
{
res = await response.Content.ReadAsStringAsync();
responseSuccessResult.StatusCode = response.StatusCode;
responseSuccessResult.Data = JsonConvert.DeserializeObject<object>(res);
uploadResult = JObject.Parse(JObject.Parse(res).GetValue("value").ToString()).GetValue("result").ToString();
fileName = JObject.Parse(JObject.Parse(res).GetValue("value").ToString()).GetValue("filename").ToString();
filePath = JObject.Parse(JObject.Parse(res).GetValue("value").ToString()).GetValue("filepath").ToString();
uploadFailedMessage = JObject.Parse(JObject.Parse(res).GetValue("value").ToString()).GetValue("data").ToString();
if (uploadResult.Equals("1"))
{
//membuat folder
var datetime = DateTime.Now.ToString("yyyyMMddHHmmssfff");
dynamic parse = JArray.Parse(data.ToString());
_htParameters["p_file_path"] = "";
_htParameters["p_file_name"] = "";
_htParameters = JsonController.setJsonToParam(jsonConvert);
try
{
_dal = new GeneralDAL(_connectionString);
_htParameters = new Hashtable();
file_name = _htParameters["p_file_name"].ToString();
file_path = _htParameters["p_file_paths"].ToString();
_htParameters["p_module"] = filePath[0];
_htParameters["p_header"] = filePath[1];
_htParameters["p_child"] = filePath[2];
_htParameters["p_acess_type"] = "PREVIEW";
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(source))
{
bool results = zip.ContainsEntry(searchFile);
if (results)
{
zip.Password = secretKey;
zip.ExtractAll(target, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);
}
}
byte[] b = System.IO.File.ReadAllBytes(target + file_name);
var base64 = Convert.ToBase64String(b);
if (System.IO.File.Exists(target + file_name))
{
System.IO.File.Delete(target + file_name);
//_dal.Insert("", "XSP_SYS_DOC_ACCESS_LOG_INSERT", _htParameters);
}
_htParameters["p_module"] = filePath[0];
_htParameters["p_header"] = filePath[1];
_htParameters["p_child"] = filePath[2];
_htParameters["p_doc_no"] = filePath[2];
_htParameters["p_acess_type"] = "PREVIEW";
[HttpPost]
[Route("Upload")]
public async Task<IActionResult> PostUploadImage([FromBody] dynamic data)
{
return await Task.Run(() =>
{
return Ok(base.PostUploadImage((JArray)data, _spNameForUploadFile));
});
}
[HttpPost]
[Route("Priview")]
public async Task<IActionResult> Priview([FromBody] dynamic data)
{
return await Task.Run(() =>
{
return Ok(base.Priview((JArray)data, _spName));
});
}
[HttpPost]
[Route("Deletefile")]
public async Task<IActionResult> Deletefile([FromBody] dynamic data)
{
return await Task.Run(() =>
{
return Ok(base.Deletefile((JArray)data, _spNameForDeleteFile));
});
}