我有一个带有NoteID的自定义对象,该对象随同导入的两个图像一起导入。我使用UploadFileMaintence图形手动构建与在代码中上传图像相关的对象。我可以看到数据库中正确链接在一起的对象,当我导航到定制详细信息页面时,文件将它们显示为已上传:
但是,当我单击Files(2)按钮时,出现对话框时,对话框中什么也没看到:
以下是四个相关的表(CustomTable,NoteDoc,UploadFile和UploadFileRevision):
CustomTable显示noteID和CheckURLName:
用于生成图像上传条目的代码:
protected void AddDetailRow(List<KeyValuePair<int, string>> keypairs, InventoryItem givingType, string temp, UploadFileMaintenance graph)
{
//NOTE string temp contains the temporary directory address I created.
CFBSContributionDetail detail = Details.Insert();
//Code to populate detail object
//NOTE: the variables front and back get populated with the file name of the image related to them.
Details.Update(detail);
this.Actions.PressSave();
PX.SM.FileInfo frontInfo = new PX.SM.FileInfo(front, null, File.ReadAllBytes(temp + front));
frontInfo.RevisionId = 1;
frontInfo.Comment = front;
frontInfo.UID = Guid.NewGuid();
PX.SM.FileInfo backInfo = new PX.SM.FileInfo(back, null, File.ReadAllBytes(temp + back));
backInfo.RevisionId = 1;
backInfo.Comment = back;
backInfo.UID = Guid.NewGuid();
PXNoteAttribute.AttachFile(Details.Cache, detail, frontInfo);
PXNoteAttribute.AttachFile(Details.Cache, detail, backInfo);
Details.Update(detail);
this.Actions.PressSave();
UploadFile frontFile = new UploadFile();
frontFile.FileID = frontInfo.UID;
frontFile.Name = front;
frontFile.Versioned = true;
graph.Files.Insert(frontFile);
UploadFileRevision frontImage = new UploadFileRevision();
frontImage.FileID = frontInfo.UID;
frontImage.Data = frontInfo.BinData;
frontImage.FileRevisionID = 1;
frontImage.BlobData = frontInfo.BinData;
frontImage.Size = frontInfo.BinData.Length;
graph.Revisions.Insert(frontImage);
graph.Actions.PressSave();
UploadFile backFile = new UploadFile();
backFile.FileID = backInfo.UID;
backFile.Name = back;
backFile.Versioned = true;
graph.Files.Insert(backFile);
UploadFileRevision backImage = new UploadFileRevision();
backImage.FileID = backInfo.UID;
backImage.Data = frontInfo.BinData;
backImage.FileRevisionID = 1;
backImage.BlobData = backInfo.BinData;
backImage.Size = backImage.BlobData.Length;
graph.Revisions.Insert(backImage);
graph.Actions.PressSave();
detail.CheckImageUrl = front;
Details.Update(detail);
this.Actions.PressSave();
}
我注意到的一件事是,存储在UploadFile-> Name列中的图像URL是屏幕类型,后跟一组随机数字。我不确定如何生成它,甚至不确定是否要生成它。我正在上传的文件为.TIF格式,但由于.TIF不会显示在浏览器中,因此我将其更改为.PNG。
如果有更好的方法来执行此任务,则我愿意完全改变到目前为止所做的事情。
编辑:我添加了将.tif文件转换为.png文件的代码,然后再上传。
答案 0 :(得分:0)
创建完FileInfo对象后,我忘记添加行graph.SaveFile(frontInfo);
和graph.SaveFile(backInfo);
。添加这些行将其修复