It is currently 20 September 2024, 2:31 Advanced search

Uploading Files and temp directory?

Questions and answers on how to best use Instant Developer

Uploading Files and temp directory?

Postby john w » 11 April 2023, 15:32

I have a process that loads data from a 3rd party app into my InDe application. The data is moved using a .txt file, uploaded and then processed by code in the InDe appplication. The .txt file is read then immediately deleted. This has worked for some time. However, now it no longers pulls the uploaded .txt file. Instead it pulls the first file in the temp directory. Often this is a .png file or .pdf file. This causes the process to fail.

Two Questions
a. Can I modify the code below to get the correct file?
b. Can I change the directory the .txt file is uploaded to?


Code: Select all

while (sfilename = "1")
{
   
sfilename = SolomonAppraisalCalculators2022.readDirectory(SolomonAppraisalCalculators2022.path() + "/temp/", ...)
  SolomonAppraisalCalculators2022.Sfilename = sfilename
  iCounter = iCounter + 1   
}

SolomonAppraisalCalculators2022.DTTMaxLoopCycles = 2000

int ifileid = 0
ifileid = SolomonAppraisalCalculators2022.freeFile()

SolomonAppraisalCalculators2022.openFileForInput(SolomonAppraisalCalculators2022.path() + "/temp/" + sfilename, ifileid, ...)
Regards

John W
User avatar
john w
 
Posts: 819
Joined: 24 October 2012, 16:29
Location: Apple Valley, Minnesota USA

Re: Uploading Files and temp directory?

Postby t.simoncini » 12 April 2023, 7:11

Well, your code simply get the first file found in the temp folder by the readDirectory function. Maybe it's the first in alphabetical order? Modification/Creation date order? Why not looking for a specific file name?

Question 1: how do you upload the txt file?
Question 2: where is located in your project the code you have posted?
t.simoncini
 
Posts: 1576
Joined: 5 March 2012, 14:00

Re: Uploading Files and temp directory?

Postby ljwilson » 12 April 2023, 11:57

I would:

Read up on the ReadDirectory command https://doc.instantdeveloper.com/eng/default.aspx?artid=ef2bbcd1-51db-11d5-91f3-f44534000000&lang=eng

  1. Give the ReadDirectory the attributes parameter, where you could filter on txt files.
  2. Loop on ReadDirectory--each call after the first call without parameters gets the next file using the same filter set in the first call. That way if you have more than one txt file in there you can process it.
  3. And you might want to create a separate directory rather than the temp one, so you don't have other stuff hanging around. I would create the new directory at the same level as the temp folder, and give it the same permissions. If you do that then you wouldn't necessarily need to worry about the attributes parameter.
.

...jack
ljwilson
 
Posts: 772
Joined: 26 November 2013, 14:15

Re: Uploading Files and temp directory?

Postby john w » 12 April 2023, 14:00

t.simonicini - I use the blob field upload process. My understanding is during the upload the process assigns a random name. It forces the upload into the .../temp/... folder. I have not seen a way to change that to another folder, nor assign a specific file name. It would be nice to be able to do that.

The code is in a procedure (function ) in a class. It runs when the Process Data button is used.

Snap_Wednesday, April 12, 2023_8h55m2s.png
Snap_Wednesday, April 12, 2023_8h55m2s.png (12.34 KiB) Viewed 1914 times


Jack - I actually have read that documentation a couple of times. I will likely put a .txt filter on the ReadDirectory. It is unlikely I will have two users using the process at the same time.
However, it would be nice to have a better process. Perhaps one that would catch the the uploaded file name and move the file to another another folder for processing. Again, I have not seen a place where that can happen.

Maybe I am making a simple process too complex...overthinking it as they say

I appreciate the feedback, it has been helpful.
Regards

John W
User avatar
john w
 
Posts: 819
Joined: 24 October 2012, 16:29
Location: Apple Valley, Minnesota USA

Re: Uploading Files and temp directory?

Postby t.simoncini » 12 April 2023, 15:37

I usually intercept the file upload in this panel event:
https://doc.instantdeveloper.com/eng/de ... 7&lang=eng
There, if you want, you can manipulate the uploaded file however you want, and then you can abort the standard upload procedure in the actual blob field using che Cancel parameter.
That's how I usually "bend" the standard blob functionality to achieve a basic file upload functionality.
t.simoncini
 
Posts: 1576
Joined: 5 March 2012, 14:00

Re: Uploading Files and temp directory?

Postby john w » 12 April 2023, 15:42

Thanks for the event reference. In reading it more closely it appears to be something I can use. Particularly if I can handle the creation of a file path and file name which is the core of the problem. Cancelling would be good as well.
Regards

John W
User avatar
john w
 
Posts: 819
Joined: 24 October 2012, 16:29
Location: Apple Valley, Minnesota USA

Re: Uploading Files and temp directory?

Postby ljwilson » 12 April 2023, 15:52

In the BeforeBlobUpdate event, if you set cancel=true you can prevent uploads, etc.

When cancel=false, you have a "handle" to the actual file, so you could then process it in the AfterBlobUploadEvent, or save it to a variable and then use that filename in your manual move button.

Then you wouldn't have to use ReadDirectory at all--you already know the filename!

2023-04-12_11-50-45.png
2023-04-12_11-50-45.png (16.52 KiB) Viewed 1903 times


My acme app also has an example in the Manual Upload form.

...jack
ljwilson
 
Posts: 772
Joined: 26 November 2013, 14:15

Re: Uploading Files and temp directory?

Postby john w » 12 April 2023, 16:33

Thanks again. I will look at the acme app. I need to make this a little more efficient and error free in the way it is handled by code. So I will be working on it. In the interim I have added the extentsion filter (*.txt) in the readDirectory function.
Regards

John W
User avatar
john w
 
Posts: 819
Joined: 24 October 2012, 16:29
Location: Apple Valley, Minnesota USA


Return to Tips & Tricks

Who is online

Users browsing this forum: No registered users and 5 guests

cron