1. Miguel Leeuwe
  2. PowerBuilder
  3. Thursday, 30 May 2024 16:03 PM UTC

Hi all,

I might be having a black-out or getting old, but I've been looking at a failing FileOpen for hours now.

Maybe someone knows what I'm doing wrong.

Using windows 10 latest version, PB 2019 R3 build 2797, running from the IDE in 32 bits.

Please see the attached sample app. The JPG file has to be in C:\temp2 unless you modify the code.

I've also tried with a PNG file, but FileOpen keeps returning a value of -1.

:s

TIA for any help,

MiguelL

Attachments (1)
Accepted Answer
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Saturday, 15 June 2024 13:48 PM UTC
  2. PowerBuilder
  3. # Permalink

@Mark G.

Yes, you're totally right. There was a hidden FileDelete() in the code. Instead of deleting the temp file that we had after retrieving the blob, it was deleting the original image.

surprised

Sorry for wasting your time guys, and Mark, thank you so much for taking the effort of trying to reproduce my case.

regards.

 

Comment
  1. Mark Goldsmith
  2. Sunday, 16 June 2024 17:22 PM UTC
No worries Miguel and you're most welcome, glad you found the issue!
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Friday, 14 June 2024 17:35 PM UTC
  2. PowerBuilder
  3. # 1

Hi all,

Just an update in case anyone runs into similar problems. The cause of all of my problems was:

 

- I'm selecting an image and show it on a dw in a picture object.

- Then I want to save this as a blob into the database, for which I have to do a FileOpen()

- The fileopen fails because once you show it on a picture control, powerbuilder LOCKS it, even if you only use readmode.

(it only cost me 2 days of my life).

regards.

Comment
  1. Miguel Leeuwe
  2. Friday, 14 June 2024 18:35 PM UTC
ah, I see where you're coming from now.

Yes, I've tried read mode with Shared for lock mode.
  1. Helpful
  1. Mark Goldsmith
  2. Friday, 14 June 2024 19:31 PM UTC
Hi Miguel,



I'm wondering if you still might have something else at play here. I just tried it with the following: having a picture control on a window, a picture object in a datawindow located in that same window and a string column with the "Display as Picture" checked in that same datawindow and, with all three referring to the same picture, I was still able to FileOpen() that picture. The FileOpen() parameters were as follows: FileOpen("C:\Users\Mark\OneDrive\Desktop\PB22.png", StreamMode!, Read!, Shared!)



Maybe I'm misunderstanding what you did or not exactly recreating what you did so I'm curious what might be different...any other information you can provide as well as your code? I know the image you're using is likely different than mine and I used a PNG versus JPG but neither should make a difference. I am using PB 2022 R3 Build 3289...maybe that's it?!



Regards...Mark
  1. Helpful 1
  1. Miguel Leeuwe
  2. Friday, 14 June 2024 20:09 PM UTC
Hi Mark, I think you might be right. There's a FileDelete() somewhere :s

I cannot access my computer right now, so I'll get back to you when I can.

Thanks!
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 30 May 2024 22:42 PM UTC
  2. PowerBuilder
  3. # 2
Hi Miguel; Q1: What MS-Windows O/S are you running under? Q2: Is TEMP2 folder accessible to the PB App (even when run in Admin mode)? Q3: Have you tried a test using PB 2022 R3 build 3356 (latest)? Regards .. Chris
Comment
There are no comments made yet.
Mark Goldsmith Accepted Answer Pending Moderation
  1. Thursday, 30 May 2024 20:18 PM UTC
  2. PowerBuilder
  3. # 3

Hi Miguel,

I'm curious why you wanted to specify EncodingUTF8!. Regardless, whether or not image files are ever UTF-8 encoded is a whole other discussion but the JPG file you provided was not BOM encoded in any way (UTF-8, UTF-16 etc.) with the respective markers at the beginning of the file.  I also don't believe the content was UTF-8 encoded at all.

Unfortunately PB still can't FileOpen() a UTF-8 encoded file without BOM and that is why you would receive a -1 when using EncodingUTF8! as it deems the file not to be UTF-8 encoded. When you don't specify the encoding then it defaults to ANSI, which is why it then worked for you and is also the only encoding that would work even if the file was UTF-8 encoded without BOM.

HTH...regards,

Mark

Comment
  1. Miguel Leeuwe
  2. Thursday, 30 May 2024 22:25 PM UTC
Hi John,

That's exactly what I am doing. Thanks for clearing up that no encoding is needed.
  1. Helpful
  1. Roland Smith
  2. Friday, 31 May 2024 03:06 AM UTC
BOM / Encoding is only for text files.
  1. Helpful 1
  1. Miguel Leeuwe
  2. Friday, 31 May 2024 07:16 AM UTC
@Roland, thanks!
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 30 May 2024 16:18 PM UTC
  2. PowerBuilder
  3. # 4

Hi, Miguel -

You've specified a nested set of string delimiters:

ls_image = '"c:\temp2\Screenshot 2021-12-28 182229.jpg"'

Remove either the apostrophes or the quote marks, and the FileOpen PowerScript function will issue a return code of 1.

Best regards, John

Comment
  1. Miguel Leeuwe
  2. Thursday, 30 May 2024 16:50 PM UTC
Thanks you John, that works!

Initially I used Shared!, but I've been playing around.

The reason why I'm specifying all of the arguments is because I want the file to be opened in EncodingUTF8!, which is the last argument for FileOpen. The help on FileOpen seems to suggest that it shouldn't be a problem and that arguments might be ignored when opening in Read mode. Obviously that's not really working. I also guess that the EncodingUTF8 is ONLY for write mode.

Well, let me see if I can get things to work.

Thank you very much!
  1. Helpful
  1. Miguel Leeuwe
  2. Thursday, 30 May 2024 16:55 PM UTC
@Chris

A1: windows 10 Version 10.0.19045.4412

A2: Yes

A3: I also tried with pb 2022 R3 3289 (not the latest) and also failed. I guess the arguments need better documentation on what to specify when opening in Read mode. I might try with the latest build when I figure things out.

regards
  1. Helpful
  1. Miguel Leeuwe
  2. Thursday, 30 May 2024 17:26 PM UTC
@Chris,

I've tried now also with the latest build of 2022 and it also failed.

When I don't specify the last argument (EncodingUTF8!) then things work. And like John said, there's really no need to specify anything after the Read! argument.
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Thursday, 30 May 2024 16:14 PM UTC
  2. PowerBuilder
  3. # 5

BTW: I put single quotes around the filename to see if that would help, but it didn't.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.