Problem downloading file after upload via the "upload" component on S3

I am testing how to use AW3 S3 file storage. I use the upload component. After the file is uploaded (and this is confirmed working), I see a link on the Upload box. However, when I click on this file name link, the file returned is an Error message rather than the original PDF file uploaded.
image

The file returned is a HTTP Status 410 - Gone error.
image

Is this working correctly ?

CK

Hi,
Are there any error or warning messages, or exceptions in server log?
Does this error happen in local debug server, or in deployed environment in AWS?

Hi,

This error happens on my local debug server. When I click on the hyperlink (eg. acme_cis.pdf) link above above, it opens another window with the following URL.

URL: http://localhost:8080/app/APP/connector/0/1/view-bdeb338e-8adf-47d8-9334-6584c974ef4f/acme_cis.pdf

But this is not a PDF.

image

There is NO errors in server.log.
Is there something wrong with the URL ?

CK

Hi,
Which version of cuba patform do you use?
Did you double check that uploaded file appared in your bucket on aws.amazon?
(see manual how to configure aws)
I can`t reporuce the problem. Uploaded file openes in browser successfully.

BR,
Yulia Maistrenko

I just created a simple, new project using 7.2.11, without using AWS storage,
and I have a screen with just this component:

<upload id="uploadField" showFileName="true"/>

Then I copied the code from the manual:
https://doc.cuba-platform.com/manual-latest/gui_FileUploadField.html

The screen comes up, the upload button works and I get all the notifications.
I uploaded a PDF. I can see the file in the External Files list. I can download the file from the External Files list screen.

But on the original test screen, when I click on the file name, in blue, on the upload field, a new tab/window opens but it is BLANK. Is this the correct behaviour ?

CK

Hi,
Which operating system and browser do you use?

I have tested on Chrome, Firefox and Edge, on Windows 10 PC, all with the same result.

I noticed that when I click on the blue file link, the URL is different from the one generated by “Download” in the External File admin page.

Generated by blue file link:
http://localhost:8080/app/APP/connector/0/1/view-c4a347a3-3da3-4097-87e7-f80a02349795/ajinomoto.pdf

Link generated from Download button on External Files in administration menu (working):
http://localhost:8080/app/APP/connector/0/1/view-506ed637-78c4-4b00-b994-24288cf82a68/ajinomoto.pdf

Please note that:

  1. I am not using the upload tag in a FieldGroup with datasource. So I don’t have fileStoragePutMode="IMMEDIATE".

  2. My XML is:
    <upload id="uploadField" showFileName="true"/>

  3. I used this code to store the file:

@Subscribe("uploadField")
public void onUploadFieldFileUploadSucceed(FileUploadField.FileUploadSucceedEvent event) {
    File file = fileUploadingAPI.getFile(uploadField.getFileId()); 
    if (file != null) {
        notifications.create()
                .withCaption("File is uploaded to temporary storage at " + file.getAbsolutePath())
                .show();
    }

    FileDescriptor fd = uploadField.getFileDescriptor(); 
    try {
        fileUploadingAPI.putFileIntoStorage(uploadField.getFileId(), fd); 
    } catch (FileStorageException e) {
        throw new RuntimeException("Error saving file to FileStorage", e);
    }
    dataManager.commit(fd); 
    notifications.create()
            .withCaption("Uploaded file: " + uploadField.getFileName())
            .show();
}

Is it because I am not using the “IMMEDIATE” mode ? And because of that the UUID is wrong ?

Hi!
I have reproduced the problem with your code.
When you uploade file, it stores in temporary storage. After the programm executes fileUploadingAPI.putFileIntoStorage(uploadField.getFileId(), fd); , file removes from temporary storage and stores in File Storage, but clicking on the blue file link still leads to temporary storage.
If you add setValue() method after commit(), the pdf file will be opened in new tab correctly
FileDescriptor committedFD = dataManager.commit(fd); uploadField.setValue(committedFD);

BR,
Yulia Maistrenko

2 Likes

OK I understand. Thanks for the clarification.