如何获得以编程方式导入的文件以显示在文件和图像显示中? [英] How do I get a programmatically imported file to show in Files and image display?

查看:100
本文介绍了如何获得以编程方式导入的文件以显示在文件和图像显示中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有NoteID的自定义对象,该对象与两个与之相关的图像一起导入。我使用UploadFileMaintence图形手动构建与在代码中上传图像相关的对象。我可以看到在数据库中正确链接在一起的对象,当我导航到定制详细信息页面时,文件将它们显示为已上传:

I have a custom object with a NoteID that I import along with two images related to it. I manually build the objects associated with uploading an image in code using an UploadFileMaintence graph. I can see the objects linked together in the database properly, and when I navigate to the custom detail page, the files show them as uploaded:

但是,当我单击Files(2)按钮时,出现对​​话框时,对话框中什么也没看到:

However, when I click on the Files(2) button, when the dialog box comes up, I see nothing within the dialog:

以下是四个相关表(CustomTable,NoteDoc,UploadFile和UploadFileRevision):

Here are the four related tables (CustomTable, NoteDoc, UploadFile, and UploadFileRevision):

CustomTable显示noteID和CheckURLName:

CustomTable showing noteID and CheckURLName:

NoteDoc显示NoteID与FileID的关系:

NoteDoc showing NoteID to FileID relationship:

上传文件:

UploadFile:

UploadFileRevision:
< img src = https://i.stack.imgur.com/l8joO.png alt =在此处输入图片描述>

UploadFileRevision:

代码为生成图像上传条目:

Code to generate image upload entries:

    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。

One thing I noticed is that the image URLs stored in the UploadFile -> Name column are the screen type followed by a random set of numbers. I'm not sure how to generate that or if I even need to generate that. The files I'm uploading are of .TIF format, but I'm going to be changing them to .PNG since .TIF do not display within the browser.

如果还有一种更好的方法可以执行此任务,我愿意完全改变到目前为止所做的事情。

If there is a better way to perform this task, I'm open to completely changing what I've done so far.

编辑:我添加了代码来转换.tif

I added code to transform the .tif files into .png files before uploading them.

推荐答案

我忘了添加 graph.SaveFile(在完成创建FileInfo对象后, graph.SaveFile(backInfo); 。添加这些行即可解决

I forgot to add the lines graph.SaveFile(frontInfo); and graph.SaveFile(backInfo); after I finished creating the FileInfo objects. Adding those lines fixed it

这篇关于如何获得以编程方式导入的文件以显示在文件和图像显示中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆