public UploadResponse Upload(UploadRequest request) { var tempFile = Path.GetTempFileName(); try { // write data to a temp file File.WriteAllBytes(tempFile, request.DataContent); // create the new document object, and put the remote file var args = new AttachedDocumentCreationArgs { MimeType = request.MimeType, FileExtension = request.FileExtension, LocalContentFilePath = tempFile }; var document = AttachedDocument.Create(args, AttachmentStore.GetClient()); PersistenceContext.Lock(document, DirtyState.New); PersistenceContext.SynchState(); var assembler = new AttachedDocumentAssembler(); return new UploadResponse(assembler.CreateAttachedDocumentSummary(document)); } finally { File.Delete(tempFile); } }
/// <summary> /// Creates a <see cref="AttachedDocument"/> instance, uploading the specified file to the document store. /// </summary> /// <param name="args"></param> /// <param name="documentStore"></param> /// <returns></returns> public static AttachedDocument Create(AttachedDocumentCreationArgs args, IAttachedDocumentStore documentStore) { // create the new document object, and put the remote file var document = new AttachedDocument { MimeType = args.MimeType, FileExtension = args.FileExtension, }; document.PutFile(documentStore, args.LocalContentFilePath); return document; }
/// <summary> /// Creates a <see cref="AttachedDocument"/> instance, uploading the specified file to the document store. /// </summary> /// <param name="args"></param> /// <param name="documentStore"></param> /// <returns></returns> public static AttachedDocument Create(AttachedDocumentCreationArgs args, IAttachedDocumentStore documentStore) { // create the new document object, and put the remote file var document = new AttachedDocument { MimeType = args.MimeType, FileExtension = args.FileExtension, }; document.PutFile(documentStore, args.LocalContentFilePath); return(document); }