acumatica

How do I get a programmatically imported file to show in Files and image display?


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: enter image description here

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

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

CustomTable showing noteID and CheckURLName: enter image description here

NoteDoc showing NoteID to FileID relationship: enter image description here

UploadFile: enter image description here

UploadFileRevision: enter image description here

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();
    }

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.

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


Solution

  • 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