我有一个带有 NoteID 的自定义对象,我将其以及与其相关的两个图像一起导入。我使用 UploadFileMaintence 图手动构建与在代码中上传图像相关的对象。我可以看到数据库中正确链接在一起的对象,当我导航到自定义详细信息页面时,文件将它们显示为已上传:
但是,当我单击“文件”(2) 按钮时,当对话框出现时,我在对话框中看不到任何内容:
以下是四个相关表(CustomTable、NoteDoc、UploadFile 和 UploadFileRevision):
NoteDoc 显示 NoteID 到 FileID 的关系:
生成图片上传条目的代码:
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 格式,但我将把它们更改为 .PNG,因为 .TIF 不会在浏览器中显示。
如果有更好的方法来执行此任务,我愿意完全改变我迄今为止所做的事情。
编辑:我添加了代码,在上传之前将 .tif 文件转换为 .png 文件。
创建 FileInfo 对象后,我忘记添加行
graph.SaveFile(frontInfo);
和 graph.SaveFile(backInfo);
。添加这些行修复了它
我尝试在网格文件中上传图像,但它在本地计算机中工作正常,但在 acumatica 实时实例中抛出错误:找不到路径 'C:\Logos'th.png 的部分' 你能帮我解决这个错误吗?
#region 操作(按钮)
public PXAction<TSBrandImages> AttachImage;
[PXProcessButton]
[PXUIField(DisplayName = "Attach Image", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
public virtual IEnumerable attachImage(PXAdapter adapter)
{
foreach (TSBrandImages img in this.BrandImages.Select())
{
//if (img.Selected == true)
//{
PX.SM.UploadFileMaintenance upload = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
UploadFile file = new UploadFile();
string imagePath = img.ImagePath;
string fileName = Path.GetFileName(imagePath);
string directoryPath = Path.GetDirectoryName(imagePath);
PX.SM.FileInfo backInfo = new PX.SM.FileInfo(fileName, null, File.ReadAllBytes(imagePath));
// upload.SaveFile(backInfo);
backInfo.RevisionId = 1;
backInfo.Comment = fileName;
backInfo.UID = Guid.NewGuid();
PXNoteAttribute.AttachFile(BrandImages.Cache, img, backInfo);
BrandImages.Update(img);
upload.SaveFile(backInfo);
this.Actions.PressSave();
UploadFile frontFile = new UploadFile();
frontFile.FileID = backInfo.UID;
frontFile.Name = fileName;
frontFile.Versioned = true;
upload.Files.Insert(frontFile);
UploadFileRevision frontImage = new UploadFileRevision();
frontImage.FileID = backInfo.UID;
frontImage.Data = backInfo.BinData;
frontImage.FileRevisionID = 1;
frontImage.BlobData = backInfo.BinData;
frontImage.Size = backInfo.BinData.Length;
upload.Revisions.Insert(frontImage);
// upload.SaveFile(backInfo);
upload.Actions.PressSave();
// }
}
return adapter.Get();
}
#endregion