Sometimes you want to upload file to Acumatica but you do not want to save it to the database. This may requires for in-place data processing or uploading data from specific format.
Today I want to show you one way, how you can allow user to upload file in the browser and handle it with your server logic.
In high level, to achieve it you need to do 3 steps
- Add special PXUploadDialog panel to your page. This control will handle file upload and save somewhere. By specifying configuration properties, you can control where Acumatica will save a file. In our case we want to store it in session.
- Defile dummy data member that will be associated with upload dialog. Buy calling Ask() method here, you will trigger panel and user will be able to upload file.
- Add button and call dummy data member from previous step. After uploading Acumatica will automatically call your method second time, and then you will be able to get file from session.
First of all we need to add a panel to our screen. Unfortunately there is no way to add it through the designer so you have to edit ASPX code. But fortunately you can do it in Visual Studio and Browser as well. IF you want to use VS, just open page and add required code. If you are using browser, that you need to go to page, click Actions->Edit ASPX and past code there.
<px:PXUploadDialog ID="pnlNewRev"runat="server" Height="120px"Style="position: static" Width="560px" Caption="Statement File Upload"
AutoSaveFile="false" RenderCheckIn="false" />
The most important points in the script above are highlighted with bold:
- Key - is link to data member in graph
- SessionKey - is unique session key name. This name will be used to save and retrieve file from session.
- AutoSaveFile - setting that advises Acumatica to not save file to database.
Go to the graph code file and define new data member that will be associated with panel. It is not important what DAC will you use for this data member, but make sure that the name is the same as Key in the panel.
public PXSelect<GLTran> NewFilePanel;
Button is your custom handler where you want to process file. Here you need to call Ask() method from data member, in this case Acumatica will show upload panel to user. If everything is OK, Acumatica will call your method second time and you can process further with your file.
Please note that Acumatica may have some file size and file types limitation. This can be changed in Upload File Preferences screen.
Also do not forget to remove file from session after processing. This will help you to save server memory. Acumatica will remove this file automatically only when session will be expired.
Acumatica will provide you a binary data of the file, so you can open it with any possible way. Also it may help you to process encrypted and special format files.
That is all, Have a nice development!