代码之家  ›  专栏  ›  技术社区  ›  EricP.

如何获取以编程方式导入的文件以在文件和图像显示中显示?

  •  0
  • EricP.  · 技术社区  · 6 年前

    我有一个带有noteid的自定义对象,它和两个与之相关的图像一起导入。我使用uploadFileMaintence图形手动构建了与在代码中上载图像相关联的对象。我可以在数据库中正确地看到链接在一起的对象,当我导航到“自定义详细信息”页面时,文件显示为已上载:

    但是,当我单击文件(2)按钮时,当对话框出现时,在对话框中看不到任何内容:

    以下是四个相关表(customtable、notedoc、uploadfile和uploadfilerevision):。

    显示noteid和checkurlname的自定义表:

    notedoc显示noteid到fileid的关系:

    上载文件:

    上载文件修订:

    生成图像上载条目的代码:

    protected void adddetailrow(list<keyvaluepair<int,string>>keypairs,inventoryitem givingtype,string temp,uploadfilemaintenance graph)
    {
    //注意字符串temp包含我创建的临时目录地址。
    cfbsContributionDetail detail=details.insert();
    //用于填充细节对象的代码
    //注意:前面和后面的变量被填充为与它们相关的图像的文件名。
    详细信息。更新(详细信息);
    
    this.actions.pressave();
    
    px.sm.fileinfo frontinfo=new px.sm.fileinfo(front,null,file.readallbytes(temp+front));
    frontinfo.revisionid=1;
    frontinfo.comment=前面;
    frontinfo.uid=guid.newguid();
    px.sm.fileinfo backinfo=新建px.sm.fileinfo(back,null,file.readallbytes(temp+back));
    backinfo.revisionid=1;
    backinfo.comment=后退;
    backinfo.uid=guid.newguid();
    pxnoteattribute.attachfile(details.cache,detail,frontinfo);
    pxnoteattribute.attachfile(details.cache,detail,backinfo);
    详细信息。更新(详细信息);
    this.actions.pressave();
    
    uploadFile frontFile=new uploadFile();
    frontfile.fileid=frontinfo.uid;
    frontfile.name=前面;
    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(正面图像);
    
    graph.actions.pressave();
    
    uploadFile backfile=new uploadFile();
    backfile.fileid=backinfo.uid;
    backfille.name=后退;
    backfille.versioned=true;
    graph.files.insert(逆火);
    
    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.pressave();
    
    detail.checkImageURL=正面;
    
    详细信息。更新(详细信息);
    
    this.actions.pressave();
    }
    

    我注意到的一件事是,存储在uploadfile->name列中的图像URL是屏幕类型,后跟一组随机数字。我不知道如何生成它,或者是否需要生成它。我要上载的文件是.tif格式,但我要将其更改为.png格式,因为.tif不在浏览器中显示。

    如果有更好的方法来执行这项任务,我愿意完全改变我迄今为止所做的工作。

    编辑:在上载.tif文件之前,我添加了将其转换为.png文件的代码。enter image description here

    但是,当我单击文件(2)按钮时,当对话框出现时,在对话框中看不到任何内容: enter image description here

    以下是四个相关表(customtable、notedoc、uploadfile和uploadfilerevision):

    显示noteid和checkurlname的自定义表: enter image description here

    notedoc显示noteid到fileid的关系: enter image description here

    上载文件: enter image description here

    上载文件修订: enter image description here

    生成图像上载条目的代码:

        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文件的代码。

    1 回复  |  直到 6 年前
        1
  •  0
  •   EricP.    6 年前

    我忘了加线了 graph.SaveFile(frontInfo); graph.SaveFile(backInfo); 在我创建完fileinfo对象之后。加上那几行就修好了