Repository navigation
Closed
Labels
Description
I tried uploading a file to serverpod_cloud_storage. It works fine. But when I try getting the public url, I ran into this exception.
Debugger traces
args: {
"path" : "PhotoViewer.m",
"auth" : "1:P4OpgPmsZ289mQnWII0cET17c5tW0CnJ",
"method" : "getDownloadUrl"
}
e: FormatException (FormatException: No deserialization found for type Uri?)
endpoint: "assets"
method: "getDownloadUrl"Endpoint code
import 'package:serverpod/serverpod.dart';
class AssetsEndpoint extends Endpoint {
Future<String?> getUploadDescription(Session session, String path) async {
try {
session.log('Path: $path');
return session.storage.createDirectFileUploadDescription(
storageId: 'public',
path: path,
);
} on Exception catch (e) {
session.log(e.toString(), level: LogLevel.error);
return null;
}
}
Future<bool> verifyUpload(Session session, String path) async {
return await session.storage.verifyDirectFileUpload(
storageId: 'public',
path: path,
);
}
Future<Uri?> getDownloadUrl(Session session, String path) async {
session.log('Path: $path');
return session.storage.getPublicUrl(
storageId: 'public',
path: path,
);
}
}I use in flutter code
uploading
? const CircularProgressIndicator.adaptive()
: ElevatedButton(
onPressed: () async {
FilePickerResult? result =
await FilePicker.platform.pickFiles(
allowMultiple: false,
);
String? uploadDescription;
if (result != null) {
setState(() {
uploading = true;
});
var name = result.files.single.name;
uploadDescription = await AppConstants.client.assets
.getUploadDescription(name);
var bytes =
File(result.files.single.path!).readAsBytesSync();
bool success = false;
if (uploadDescription != null) {
var uploader = FileUploader(uploadDescription);
var a = ByteData.sublistView(bytes);
success = await uploader.uploadByteData(a);
var uploaded =
await AppConstants.client.assets.verifyUpload(name);
var exists = await AppConstants.client.assets
.checkFileExists(name);
print('Uploaded: $uploaded');
print('Exists: $exists');
if (exists) {
var a = await AppConstants.client.assets
.getDownloadUrl(result.files.single.name);
print(a?.toString());
await Fluttertoast.showToast(
msg: '$uploadDescription $success',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 5,
backgroundColor:
success ? Colors.green : Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
}
setState(() {
uploading = false;
});
}
}
},
child: const Text('Upload and get URL'),
),serverpod_cloud_storage table
| id | storageId | path | addedTime | expiration | byteData | verified |
|---|---|---|---|---|---|---|
| 1 | public | PhotoViewer.m | 2022-12-03 21:39:10.476641 | NULL | BINARY (13 KB) | TRUE |
Reacted by braj065 and Elian Ortega
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone 🚀
Activity
yahu1031 commentedon Dec 3, 2022
UPDATE: Fix Found in
serverpod_serialization/lib/src/serialization.dartvlidholt commentedon Dec 7, 2022
Uriis currently not supported by the serialization layer. This would be a great future feature though.yahu1031 commentedon Dec 7, 2022
@vlidholt So should I make a PR with this fix?
vlidholt commentedon Dec 7, 2022
It also needs tests and correct serialization for the database.
realkhalife commentedon Dec 12, 2022
Anytime i try to use
session.db.queryi still got the same errorFormatException: No deserialization found for type dynamicrealkhalife commentedon Dec 14, 2022
@yahu1031 can you help me out ?
yahu1031 commentedon Dec 14, 2022
@realkhalife sure but that need to be changed in framework level and that won't work on deployment. Cause serverpod(changed code) doesn't exist there in server.
realkhalife commentedon Dec 14, 2022
i see, thank you. can't wait for the fix in future upgrades
II11II commentedon Dec 17, 2022
Ill create PR for this, after the PR #493 is going to be merged
yahu1031 commentedon Dec 18, 2022
@II11II also check out the solution I gave. 😇
II11II commentedon Dec 18, 2022
Yes sure
vlidholt commentedon Dec 18, 2022
Very cool. I think after doing the Duration one, this should be straight forward. :)
yahu1031 commentedon Dec 19, 2022
@II11II If you want me to create one, I can do it.
II11II commentedon Dec 19, 2022
@yahu1031 I do not mind)
Please confirm, when you start creating pr
1 remaining item
yahu1031 commentedon Dec 19, 2022
@II11II Done created one 😄
mozexty commentedon Mar 14, 2023
I updated Serverpod from 1.0.0 to 1.0.1. Then every new endpoint I write gives me this error, even if the returned class contains a single String.
FormatException: No deserialization found for type dynamic #0 SerializationManager.deserialize (package:serverpod_serialization/src/serialization.dart:77:5) #1 Protocol.deserialize (package:nusape_server/src/generated/protocol.dart:456:18) #2 EndpointDispatch._formatArg (package:serverpod/src/server/endpoint_dispatch.dart:163:33) #3 EndpointDispatch.handleUriCall (package:serverpod/src/server/endpoint_dispatch.dart:106:25) <asynchronous suspension> #4 Server._handleRequest (package:serverpod/src/server/server.dart:224:18) <asynchronous suspension>Old endpoints are working correctly.
I checked #536 , #237 , #498.
fischerscode commentedon Mar 14, 2023
The methods in your endpoint must explicitly return a
Future<String>(add it in front of your method name).After a
serverpod generate, it should work.If it doesn't, please create a new issue and include an example.
mozexty commentedon Mar 14, 2023
Yes it works. But I need to return an object with many fields.
Is returning
Future<String>a temporary solution?My other endpoints are returning Serverpod-generated classes successfully.