App not generating base64 Image correctly

I have my app that generates a base64 string as the b64data variable that I’m sending to the server and then decoding in PHP server-side. The base64 image it generates is linked in below since it’s so long and the code below is from my app function that generates the base64. Having trouble understanding where the error is in the base64 image syntax. Any help is appreciated!

Link to base64 code generated by my app

function capturePhoto() {
	Camera.capturePhoto(200,200)
		.then(function (photo) {
			photo.save()
				.then(function(filePath) {
					console.log("Photo saved to: " + filePath);
					var arrayBuff = FileSystem.readBufferFromFileSync(filePath);
					b64data = Base64.encodeBuffer(arrayBuff); // send this to the backend
					photo.release();
				})
				.catch(function(error) {
					console.log("Failed to save photo: " + error);
					photo.release();
				});
		})
		.catch(function (error) {
			console.log("Failed to capture photo: " + error);
		});
}

Please share the original image from the camera.

This code works correctly with the image from the disk.

var arrayBuff = FileSystem.readBufferFromFileSync(filePath);
var b64data = Base64.encodeBuffer(arrayBuff);
console.log(b64data);

I found that the issue is that my base64 isn’t sending the entire string and instead is cut short. I am using the following fetch function:

function submitPhoto(){ 


fetch('http://fanbeauties.com/app/submit-photo.php?pass=MY_PASS', { 
    method: "POST", 
    headers: {
      "Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
    },
    body: 'name='+name+'&email='+email+'&market='+market+'&picture='+b64data
     });


};

The b64data variable is too long to send completely so I don’t know what to do?

Javascript should not be restricted. Look at the settings of the server to the maximum size of the POST request. You can also try using multipart/form-data instead of application/x-www-form-urlencoded.

The POST limits have been increased yesterday. Then I tried multipart/form-data and none of the data sent at all.

You also need to check the processing of incoming data by the server. Perhaps some characters are escaped. I do not see in your code base64 sign “+”. Most likely it is replaced with something.

I did as well. If I change the code in my PHP file right on the server to my full base64 string then it works great server-side. The issue is that for some reason when the app sends the base64 to the server it gets cut off. The base64 string is huge I know. On server-side it isn’t an issue because my PHP creates a JPG out of it anyway. I just need to get that huge string to POST!

Could you share the contents of the base64 from the console.log(base64) and the result of the base64 on the server. It should be the same image.

My code works. The server receives the correct string of base64. Fuse Version 1.7.2.

var filePath = "D:/Dropbox/Projects/Fuse/Project1/Code/Assets/images/image.jpg";
var action = "upload";
var email = "email";
var market = "market";

var arrayBuff = FileSystem.readBufferFromFileSync(filePath);
var b64data = Base64.encodeBuffer(arrayBuff);

console.log(b64data);

fetch(serverUrl, { 
    method: "POST", 
    headers: {
        "Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
    },
    body: 'action='+action+'&email='+email+'&market='+market+'&picture='+b64data
});

Well the image is being taken with the Fuse Camera View as follows. Not sure if maybe the image is too high res or something?

<!-- Camera View -->

					
				<Panel Dock="Fill">
					<CameraView.PhotoLoaded PhotoCaptureImageSource="_photoCaptureImageSource">
						<Set _cameraPreview.Visibility="Visible" />
						<Set _nativeViewHost.Visibility="Hidden" />
					</CameraView.PhotoLoaded>
					<Panel ux:Name="_cameraPreview" Visibility="Hidden">
						<Panel HitTestMode="LocalBoundsAndChildren" Alignment="Bottom" Width="72%" Margin="0,0,0,8">
							<Rectangle Layer="Background" CornerRadius="8" Opacity="0.65">
								<SolidColor Color="#fff" />
							</Rectangle>
							<Clicked>
								<Set _cameraPreview.Visibility="Hidden" />
								<Set _nativeViewHost.Visibility="Visible" />
							</Clicked>
							<Text Value="DISMISS" Margin="4" TextColor="#000" Alignment="Center" />
						</Panel>
						<Image StretchMode="UniformToFill">
							<CameraView.PhotoCaptureImageSource CameraView="_camera" ux:Name="_photoCaptureImageSource"  />
						</Image>
					</Panel>
					<NativeViewHost ux:Name="_nativeViewHost">
						<CameraView ux:Name="_camera" PreviewStretchMode="UniformToFill" ClipToBounds="true" />
					</NativeViewHost>
				</Panel>
				<!-- /Camera View -->

I think that photo resolution is not a problem. Please share the contents of base64 from console.log (base64) from the application and the result of base64 on the server. It must be the same image. I want to compare the content of the base64.

Ok getting those now. This is also the code that generates the b64data which is most likely different than yours.

function capturePhoto() {
	Camera.capturePhoto(5,5)
		.then(function (photo) {
			photo.save()
				.then(function(filePath) {
					console.log("Photo saved to: " + filePath);
					var arrayBuff = FileSystem.readBufferFromFileSync(filePath);
					b64data = Base64.encodeBuffer(arrayBuff); // send this to the backend
					photo.release();
				})
				.catch(function(error) {
					console.log("Failed to save photo: " + error);
					photo.release();
				});
		})
		.catch(function (error) {
			console.log("Failed to capture photo: " + error);
		});
}

Ok I have the base64 as received by the PHP linked in here.

It was too long to even upload here as a file.

The console.log (b64data) output is also required from the application for the same image. I want to compare the contents of base64 in the application and on the server for the same image.

function capturePhoto() {
	Camera.capturePhoto(5,5)
		.then(function (photo) {
			photo.save()
				.then(function(filePath) {
					console.log("Photo saved to: " + filePath);
					var arrayBuff = FileSystem.readBufferFromFileSync(filePath);
					b64data = Base64.encodeBuffer(arrayBuff); // send this to the backend
					//###############
                                        console.log(b64data); //Send me the result
                                        //###############
                                        photo.release();
				})
				.catch(function(error) {
					console.log("Failed to save photo: " + error);
					photo.release();
				});
		})
		.catch(function (error) {
			console.log("Failed to capture photo: " + error);
		});
}

Well now I’m working on getCameraInfo and I believe if I could set the resolution to maybe 600x600 I can make this work. Below is the code I am working on.

function getCameraInfo() {
	Camera.getCameraInfo()
		.then(function(info) {
			console.log("photoResolution: " + info[Camera.INFO_PHOTO_RESOLUTIONS]);
			console.log("captureMode: " + info[Camera.INFO_CAPTURE_MODE]);
			console.log("flashMode: " + info[Camera.INFO_FLASH_MODE]);
			console.log("cameraFacing: " + info[Camera.INFO_CAMERA_FACING]);
			console.log("supportedFlashModes: " + info[Camera.INFO_SUPPORTED_FLASH_MODES].join());

			captureMode.value = info[Camera.INFO_CAPTURE_MODE];
			flashMode.value = info[Camera.INFO_FLASH_MODE];

			if (Camera.INFO_PHOTO_RESOLUTIONS in info) {
				var availableResolutions = info[Camera.INFO_PHOTO_RESOLUTIONS];
				availableResolutions.forEach(function(e) {
					console.log(600 + "x" + 600);
				});
				photoResolution = availableResolutions[Math.floor(availableResolutions.length * 0.4)];

				var options = {};
				options[Camera.OPTION_PHOTO_RESOLUTION] = photoResolution;

				Camera.setPhotoOptions(options)
					.then(function() {
						console.log("New photo options set: " + JSON.stringify(options));
					})
					.catch(function(error) {
						console.log("Failed to set photo options: " + error);
					});
			}
		})
		.catch(function(err) {
			console.log("Failed to get camera info: " + err);
		});
}
getCameraInfo();

Also, referring to the documentation at https://www.fusetools.com/docs/fuse/controls/cameraviewbase/setphotooptions_62888d26

It is necessary to search for a problem in difference of the sent data base64 (through console.log (b64data)) and received (PHP $ _POST). Share the result of console.log (b64data) and base64 on the server for the same image. Until you share this data - I can not help.