public MessageObjectPO<UploadPO> OnPostUpload(UploadRO uploadRO) {
var response = new MessageObjectPO<UploadPO>();
Guid guid = Guid.NewGuid();
string FilePath = _serverSettings.SafetyRuleTempPath + "\\" + guid + "\\";
DirectoryInfo di = new DirectoryInfo(FilePath);
if (!di.Exists) {
di.Create();
}
using (var stream = System.IO.File.Create(FilePath + "\\" + uploadRO.fileName)) {
byte[] bytes = uploadRO.content;
stream.Write(bytes, 0, uploadRO.content.Length);
response.Data = new UploadPO() {
Edition = DateTime.Now.DayOfYear,
Revision = 0,
MinorVersion = 0,
OperativeFrom = DateTime.Now,
VersionFileSharePointPath = FilePath.Replace(@"\\", @"\"),
VersionFileName = uploadRO.fileName,
VersionFileSize = uploadRO.fileSize / 1024 / 1024,
VersionId = Guid.NewGuid(),
};
}
response.StatusCode = HttpStatusCode.OK;
return response;
}
 public class UploadRO {
public string uid { get; set; }
public string fileName { get; set; }
public int fileSize { get; set; }
public byte[] content { get; set; }
}
function onSaveRequest(
files: UploadFileInfo[],
options: { formData: FormData; requestOptions: any },
onProgress: (uid: string, event: ProgressEvent<EventTarget>) => void
): Promise<{ uid: string }> {
const currentFile = files[0] as UploadFileInfo;
const uid = currentFile.uid;
const saveRequestPromise = new Promise<{ uid: string }>( (resolve, reject) => {
// as currently configured it is impossible to request a save from the UI if there are validation errors, but that can be changed so keeping this check in place
if (currentFile.validationErrors && currentFile.validationErrors.length > 0) {
reject({ uid: uid });
} else {
const reader = new FileReader();
// onload is executed when the load even is fired i.e. when content read with readAsArrayBuffer, readAsBinaryString, readAsDataURL or readAsText is available
reader.onload = () => {
if (reader.result && typeof reader.result === "string") {
// stripping the data-url declaration as per https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL
const base64Result = reader.result.split(",")[1];
// update viewModel and resolve
const fileUpload: IFileUploadViewModel = { uid: uid, fileName: currentFile.name, fileSize: currentFile.size!, content: base64Result};
Handler_Upload(fileUpload);
resolve({ uid: uid });
} else {
reject({ uid: uid });
}
};
// onprogress is fired periodically as the FileReader reads data and the ProgressEvent can be passed directly to the Upload control, handy!
reader.onprogress = (data) => {
reader.readAsArrayBuffer(currentFile.getRawFile!())
console.log(data)
onProgress(uid, data);
};
// if the read is not completed due to error or user intervention, reject
reader.onabort = () => {
reject({ uid: uid });
};
reader.onerror = () => {
reject({ uid: uid });
}; reader.readAsDataURL(currentFile.getRawFile!());
}
}); return saveRequestPromise;
}
const pageTable = (
<div>
<Upload
{...fileProps}
batch={false}
multiple={false}
defaultFiles={[]}
showFileList={true}
restrictions={{
allowedExtensions: [".pdf"],
}}
withCredentials={true}
onAdd={onAdd}
onProgress={onProgress}
onStatusChange={onStatusChange}
onBeforeUpload={onBeforeUpload}
onRemove={onRemove}
saveUrl={onSaveRequest}
/>
</div>
)
return <>{pageTable}</>
  beforeUpload(file, fileList) {
var reader = new FileReader();
const image = new Image();
var height;
var width;
var base64Url;
//因为读取文件需要时间,所以要在回调函数中使用读取的结果
reader.readAsDataURL(file); //开始读取文件
reader.onload = (e) => {
image.src = reader.result;
image.onload = () => {
height = image.naturalHeight;
width = image.naturalWidth;
base64Url= e.target.result, //cropper的图片路径
}
}
return false;
}

最新文章

  1. CLR via C#(10)-参数
  2. 【Android】应用程序启动过程源码分析
  3. C#~使用FileSystemWatcher来监视文件系统的变化
  4. 【巧妙】【3-21个人赛】Problem C 01串
  5. No persister for 编译器每行执行两次的解决方法
  6. ubuntu12.04中如何设定中文输入法
  7. DEMO阶段已完成,今天,要深入钻
  8. VS2003&quot;无法启动调试 没有正确安装调试器&quot;的解决方法
  9. php 单引号,双引号,反引号区别
  10. linux_DNS
  11. [模板] 区间mex &amp;&amp; 区间元素种数
  12. Groovy 设计模式 -- 责任链模式
  13. 出现No package gcc+ available解决办法
  14. sql视图显示数据不对应
  15. redux进一步优化
  16. Linux redhat 7 进入单用户模式
  17. http://blog.csdn.net/w_e_i_/article/details/70766035
  18. Ajax复习
  19. Hadoop 高可用(HA)的自动容灾配置
  20. Asp.Net发送手机验证码

热门文章

  1. C - Functions again CodeForces - 789C
  2. 向mysql插入数据报错 pymysql.err.DataError: (1406, &quot;Data too long for column &#39;class&#39; at row 1&quot;) 解决方案
  3. Tomcat配置中的java.lang.IllegalStateException: No output folder问题
  4. linux下启动jar包
  5. Java中Set里remove详解
  6. CH582m模拟JoyStick使用USB与电脑通信
  7. python_类 对象 属性
  8. pycharm字体大小设置
  9. 7、Taylor公式(泰勒公式)通俗+本质详解
  10. hexo博客重新部署