Share image from `expo assets` using expo-sharing produces mysterious error - react-native

I am using latest expo-47 with dev-client i have taken care of creating custom dev-client that includes the libraries that i am using on the given code.
So i will explain my case ( i am targeting android ) :
Inside the local expo assets i have 30 images
I want to allow the user to share the images using expo-sharing but i am getting error [ see end of post ]
Below is an example of many codes i have tried it just doesn't work :
import * as Sharing from 'expo-sharing'
async function shareImage(imageURI) {
try {
await Sharing.shareAsync(require('../../../assets/images/motivational/36.jpg'))
} catch (error) {
console.log(error)
}
}
The error is the below :
[Error: Argument of an incompatible class: class java.lang.Double cannot be passed as an argument to parameter expecting class java.lang.String.]
What is this supposed to mean ?
I HAVE of course verified that the image exists on the given path

Remove the require statement from .shareAsync.
Write it like this :
await Sharing.shareAsync('../../../assets/images/motivational/36.jpg')
-OR-
Define the path before hand and call it as
await Sharing.shareAsync(imageURI).
Let me know if this solves it.

Related

Flutter test - verifying assets exist

I have a flutter app which contains a large list of quotes, each with an associated audio file.
I've written a simple test that verifies all the specified audio files are where they're supposed to be, in case of typos etc:
test('specified audio file should exist for all quotes', () {
ALL_QUOTES.forEach((quote) {
final expectedPath = 'assets/${quote.filename}.wav';
final exists = new File(expectedPath).existsSync();
expect(exists, isTrue, reason: '$expectedPath does not exist');
});
});
This passes fine in IntelliJ, however running from the command line using flutter test it fails on the first thing it looks for.
Is there a way of doing this which will work regardless of how it's run? Why does it pass one way but not the other?
Ok so I got to the bottom of this, and it is something you can do in a unit test.
To diagnose, I added the line print(Directory.current); to the test. Running in IntelliJ, I get /home/project_name. From the command line, it's /home/project_name/test. So just a simple file path thing to resolve.
Edited to include Ovidiu's simpler logic for getting the right asset path
void main() {
test('specified audio file should exist for all quotes', () {
ALL_QUOTES.forEach((quote) {
final expectedPath = 'assets/${quote.filename}.wav';
final exists = _getProjectFile(expectedPath).existsSync();
expect(exists, isTrue, reason: '$expectedPath does not exist');
});
});
}
File _getProjectFile(String path) {
final String assetFolderPath = Platform.environment['UNIT_TEST_ASSETS'];
return File('$assetFolderPath/$path');
}

Option result in akka-http

I'm having an issue when trying to return an Option result from aka-http.
Basically it's a get that might have a 404.
pathPrefix("contacts" / Segment) { id =>
get {
contactService.getById(id).map {
case Some(c: ContactDto) => complete(OK -> toResource(c))
case None => complete(HttpResponse(NotFound))
}
}
}
Which gives me and error of:
[error] found : scala.concurrent.Future[akka.http.scaladsl.server.StandardRoute]
[error] required: akka.http.scaladsl.server.Route
[error] (which expands to) akka.http.scaladsl.server.RequestContext => scala.concurrent.Future[akka.http.scaladsl.server.RouteResult]
[error] contactService.getById(id).map {
Any help would be greatly appreciated.
The problem you are seeing here has to do with the fact that you are using a Future and not because of the Option. I'm going to assume that the call contactService.getById(id) returns a Future. As the result of any route within your routing tree needs to be a Route (short for RequestContext => Future[RouteResult]) and your Future is itself not a Route, then you need to make a small change to handle this situation. You should be able to use the onComplete directive in combination with your Future as follows:
pathPrefix("contacts" / Segment) { id =>
get {
val fut = contactService.getById(id)
onComplete(fut){
case util.Success(Some(c: ContactDto)) =>
complete(OK -> toResource(c))
case util.Success(None) =>
complete(HttpResponse(NotFound))
case util.Failure(ex) =>
complete(HttpResponse(InternalServerError))
}
}
}
This code now handles the 3 possible outcomes from the Future (success with a Some, success with a None and a failure), producing a Route for each of those cases. This should fix your problem.
#cmbaxter's answer is correct but if you're happy with the standard status codes for the three cases above (Ok, NotFound, InternalServerError) then you can simplify the code to just complete directly with your function that returns Future[Option[T]].
pathPrefix("contacts" / Segment) { id =>
get {
complete(contactService.getById(id).map(toResource))
}
}
That is assuming that toResource returns a type where a ToEntityMarshaller exists for the type returned by that function. Akka provdes the machinery for Future and Option so you just need to supply the T part. For example if you were returning json and using spray-json then you can define a JsonWriter[T] and the implicits in akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport will do the rest. See spray-json-support.
The map(toResource) may not actually be required, but I'm assuming that does additional conversion of ContactDto to some other type - if its just converting it to json or similar then you can drop it and use the in built marshalling support as described above.

invalid 'in' operand profile in worklight.js

I have two Worklight apps an one SQL-adapter in one project. the first app is the client app and works perfectly well. the second one is the the managment app which is using the same SQL-Adapter. they also call the same procedure, which makes a SQL-statement and returns the results. But when initializing the procedure from the controller app I am getting an error:
TypeError: invalid 'in' operand profile worklight.js:4039
Adapter-Procedure:
var selectStatement = WL.Server.createSQLStatement("select TITLE, BODY, DATE from MESSAGES where DATE>?");
function getMessages(param1) {
return WL.Server.invokeSQLStatement({
preparedStatement : selectStatement,
parameters : [param1]
});
}
Call from the Controller:
function getMessages(){
console.log("lala");
var invocationData = {
adapter : 'ClientAdapter',
procedure : 'getMessages',
parameters: ['2014-07-21 00:00:00.000000']
};
WL.Client.invokeProcedure(invocationData, {
onSuccess : success,
onFailure : failure
});
function success(result){
console.log("Successfully gathered Messages");
}
function failure(ErrorObject){
console.log("ERROR: could not get Messages/n" + ErrorObject);
}
}
I don't get how there can be an error there because i never touch that file (to be honest: I don't even know where it's located in my Project) and in the web inspector it looks the same in both apps.
The only difference is that I'm using Bootstrap in the contorller app instead of jquery mobile.
Any ideas how to fix it or work around?
Sincerely
Max
EDIT: Added code

Cuploadfile instance not compared to null although no file instance is provided?

public function actionCreate()
{
$model=new Patient('patientScenario');
if(isset($_POST['Patient']))
{
$model->attributes=$_POST['Patient'];
$model->image= CUploadedFile::getInstance($model,'image');
if($model->save())
{
$imagePath = Yii::app()->params['DataFolder'];
if($model->image!="")
{
if(!(file_exists($imagePath)))
{
mkdir($imagePath,'0777',true);
}
}
$model->image->saveAs($imagePath.$model->id.'_'.$model->image->name);
$ns=new newserver(); $ns->uploadFile($filepath,$imagePath.$model->id.'_'.$model->image->name, $model->id.'_'.$model->image->name);
}
}}
It is a action with lot of codes I have simplified it to focus on the issue here.
The issue is while creating a patient, If I upload a image its working fine, But even though I don't upload an image the condition $model->image!="" became true and obviously there will be no file name and while trying to upload on the new server class I get
fopen(22522_): failed to open stream: No such file or directory
I tried ($model->image!==NULL) as well. still getting the same error.
But it works fine in my localhost, But not in the server.
Your problem is on newserver() class
On that class you are tried to open a file .
Check condition before the file open on newserver() class
or give a code on newserver Class

Play 2.1 - WS API - Missing Type Param Compile Error - WS.url(...).get().map { r => ... }

The error missing parameter type for response is given when I try to compile this code which comes (almost) directly from the Play 2.1 Docs
def feedTitle(feedUrl: String) = Action {
Async {
WS.url(feedUrl).get().map { response =>
Ok("test")
}
}
}
So then I give it a type like this, {response: WS.Response => ...} but then I get this error:
type mismatch;
found : play.libs.WS.Response => play.api.mvc.SimpleResult[String]
required: play.libs.F.Function[play.libs.WS.Response,?]
I think your imports are wrong. It should be play.api.libs.ws.WS instead of play.libs.WS.Response.
See http://www.playframework.com/documentation/api/2.1.0/scala/index.html#play.api.libs.ws.Response
My problem was that I imported play.libs.WS and not play.api.libs.ws.WS (notice the api package). I had to also import scala.concurrent.ExecutionContext.Implicits.global but the error message told me to do so, so that was simple.