In linux rest post example with basic authentication and base64 image in the body part

Just starting out? Need help? Post your questions and find answers here.
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

In linux rest post example with basic authentication and base64 image in the body part

Post by LiK137 »

Hi,
I'd like to know whether it is possible from linux to post data to server with basic authentication to send data in base64 encoding using rest api. Unfortunately could not find purebasic example, only Java and C# for Windows implementations available in internet.
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: In linux rest post example with basic authentication and base64 image in the body part

Post by infratec »

viewtopic.php?p=521613#p521613

Code: Select all

*Auth = UTF8("User:Password")
If *Auth
  Auth$ = Base64Encoder(*Auth, MemorySize(*Auth))
  FreeMemory(*Auth)
EndIf

Header$ + "Authorization: Basic " + Auth$ + #CRLF$
Last edited by infratec on Wed Apr 05, 2023 8:27 pm, edited 3 times in total.
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

Re: In linux rest post example with basic authentication and base64 image in the body part

Post by LiK137 »

Thank You very much for reply.
What if the Base64 encoded string length is greater than 65K, assume 10MB.
Should it work with SendNetworkString or SendNetworkData in one send or should it be separated and sent in loop until all data sent?
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: In linux rest post example with basic authentication and base64 image in the body part

Post by infratec »

Why does someone send a large file in base64 :?:

It is simply larger and has no benefits.
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

Re: In linux rest post example with basic authentication and base64 image in the body part

Post by LiK137 »

What if in case large file? Sender doesn't care about size, just select photo by thumbview (Due to camera high quality issue size of images above 1 megabytes) and push the button. And question is whether the solution link You mentioned applicable to such bigger than 65K (usually 1-3 megabytes) files?
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: In linux rest post example with basic authentication and base64 image in the body part

Post by infratec »

You should be able to send large files. (I never tried it with PB, so simply give it a try)
But still: base64 is always 30% larger then the binary file.
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

Re: In linux rest post example with basic authentication and base64 image in the body part

Post by LiK137 »

Thank You very much for reply.
You mean it is possible sending large file in only one post without breaking into smaller parts in a loop?
Then what about TCP packet size limitation?
Post Reply