Forum Discussion

DucTran's avatar
DucTran
Ideator I
6 years ago
Solved

upload a simple file to vault

Hi everyone,

I try to make an app with aras.iom by C#. I want to upload a file to vault with code:

...

Item item_File_thumb = this.inn.newItem("File", "add");
item_File_thumb.setProperty("filename", myFilename);
item_File_thumb.attachPhysicalFile(myFilepath);

Item item_File_thumb_result = item_File_thumb.apply();

...

My app is stuck at apply() so it's not return any error.

Then, I try another way:

...

Item item_File_thumb = inn.newItem("File", "add");
item_File_thumb.setProperty("filename", myFilename);
item_File_thumb.setProperty("actual_filename", myFilePath);
item_File_thumb.setProperty("checkedout_path", myDir);
Item located = item_File_thumb.createRelationship("Located", "add");
located.setProperty("related_id", "67BBB9204FE84A8981ED8313049BA06C"); // default vault

IomFactory factory = new IomFactory();
Aras.IOME.CheckinManager cm = factory.CreateCheckinManager(item_File_thumb);
Item result = cm.Checkin(1);

...

but it still not working. After Checkin(), everything is paused. because no return error so I do not know what's wrong.

Pls, help.

  • Hello,

    As Angela has said, I'm not seeing anything wrong with your code itself. I tried running the same code in an IOM app on my local machine, and I was able to upload the file successfully. For reference, the exact code I used can be seen below:

    // Login variables defined above and intentionally left out of sample
    HttpServerConnection conn = IomFactory.CreateHttpServerConnection(url, database, username, password);
    Item res = conn.Login();
    // Make sure we logged in correctly
    if (res.isError())
    {
        Console.WriteLine("Could not log in");
        return;
    }
    // Upload the file
    Innovator inn = new Innovator(conn);
    Item file_upload = inn.newItem("File", "add");
    file_upload.setProperty("filename", "test.txt");
    file_upload.attachPhysicalFile(@"C:\Temp\test.txt");
    file_upload.apply();
    // Check that the file uploaded successfully
    if (file_upload.isError())
    {
        Console.WriteLine("Could not upload file");
    }
    // Let us know if the file uploaded successfully
    Console.WriteLine("File uploaded");

    This leads me to believe that the issue is not with your code itself. I think the issue might be that the computer permissions on the physical file itself might be preventing this upload. Could you try to check those permissions (in the Windows explorer, Right-click -> Properties -> Security)? Could you also try to upload the same file as the same user through the Innovator client?

    Chris

10 Replies

  • Your first variant should do the job already, but  this.inn.newItem does looks strange. Have you tried inn.newItem?

    • DucTran's avatar
      DucTran
      Ideator I

      I have already remove "this" but it's still not working T__T

  • Is your path correct? Do you have changed the permission in your server folder so Innovator can access the folder (if you don´t use a codetree location)?

    string fileString = "bestfileever.txt";
    string path = @"C:\\temp\\Aras\\test\\" + fileString;

    Item fileItem = inn.newItem("File", "add");

    fileItem.setProperty("filename", fileString);
    fileItem.attachPhysicalFile(path);
    Item checkin_result = fileItem.apply();

    if (checkin_result.isError()){
    inn.newError("Error" + checkin_result.getErrorDetail());
    }

    • DucTran's avatar
      DucTran
      Ideator I

      I sure my path is correct.

      The "server folder", your mean is the VAULT FOLDER on server? The VAULT FOLDER is read only by default, I do not edit anything.

      I can create new File (TOC > File Handling) by manual, so i think the permission for File item is enough.

  • The Method is intended that you upload files to the Vault that are somewhere on the server. The folder in my example is some temporary folder I created at the C: drive. You normally just story files temporary there and immediately delete them after upload to the vault. The server Method will not work when you want to upload files from client side.

    • DucTran's avatar
      DucTran
      Ideator I

      I make a stand alone application with Aras API, it's not a server method. My file and path on local PC.

      • The path on local PC is correct.
      • The permission of item is enough 

      but it's still not working and no return error :(

      • christopher_gillis's avatar
        christopher_gillis
        New Member

        Hello,

        As Angela has said, I'm not seeing anything wrong with your code itself. I tried running the same code in an IOM app on my local machine, and I was able to upload the file successfully. For reference, the exact code I used can be seen below:

        // Login variables defined above and intentionally left out of sample
        HttpServerConnection conn = IomFactory.CreateHttpServerConnection(url, database, username, password);
        Item res = conn.Login();
        // Make sure we logged in correctly
        if (res.isError())
        {
            Console.WriteLine("Could not log in");
            return;
        }
        // Upload the file
        Innovator inn = new Innovator(conn);
        Item file_upload = inn.newItem("File", "add");
        file_upload.setProperty("filename", "test.txt");
        file_upload.attachPhysicalFile(@"C:\Temp\test.txt");
        file_upload.apply();
        // Check that the file uploaded successfully
        if (file_upload.isError())
        {
            Console.WriteLine("Could not upload file");
        }
        // Let us know if the file uploaded successfully
        Console.WriteLine("File uploaded");

        This leads me to believe that the issue is not with your code itself. I think the issue might be that the computer permissions on the physical file itself might be preventing this upload. Could you try to check those permissions (in the Windows explorer, Right-click -> Properties -> Security)? Could you also try to upload the same file as the same user through the Innovator client?

        Chris

  • Can You share how to get filepath  ? I am not getting exact one