victordiaz / PHONK

PHONK is a coding playground for new and old Android devices
https://phonk.app
GNU General Public License v3.0
460 stars 25 forks source link

different behavior when it should be the same #1

Closed danidask closed 4 years ago

danidask commented 6 years ago

Hi, I'm working in an app to upload a picture to a server, and I'm experimenting a weird behavior. In the flowing code, when I use filename1 inside data it crashes, but when I use filename2 it works flawlessly, but both should be the same. Is it something I did wrong or is a bug? (btw, when it crashes, how can i read the log or see whats going on?)

Thanks Victor for your work, awesome project!

ui.addTitle(app.name)

var url = 'http://192.168.1.159:9000/addpic'

ui.addButton('Upload picture', 0.8, 0.6, 0.19, 0.09).onClick(uploadPicture)

function uploadPicture() {
  var prefix = 'pic'
  var num = 1
  var extension = '.png'

  // this two should be the same:
  var filename1 = prefix + num + extension
  var filename2 = 'pic1.png'

  console.log(typeof(filename1))
  console.log(typeof(filename2))
  console.log('"' + filename1 + '"')
  console.log('"' + filename2 + '"')
  if (filename1 === filename2){
    console.log("same")
  }
  else {
    console.log("different")
  }
  // When I use filename2 here, it works. With filename1 it crashes
  var data = [{ 'name' : 'userfile', 'content' : filename1, 'type' : 'file', 'mediaType': 'image/png'}]
  network.httpPost(url, data, function (e) {
    console.log(e)
  })
}
victordiaz commented 6 years ago

Hi @danidask, can you provide me in a gist a server code sample? I changed sometime ago the HTTP POST library and might be not well tested.

If you want to see the log, the best is to have ADB installed in your system adb logcat

I will create a new issue to introduce a logging mechanism that writes up in a .log file

danidask commented 6 years ago

Ok, this is the server's code, but you can test it even if there is no server listening. https://gist.github.com/danidask/e6ad97fee659062cb5449d96038d1b85

victordiaz commented 6 years ago

Apparently the Javascript Engine (Mozilla Rhino) has a different data type for a concat String. Adding toString seems to solve the problem 334bcc1d228214a5a382fb0266e28fcf598f3fe7

On the other side I included a logging mechanism https://github.com/victordiaz/phonk/issues/2

I'm going to fix a couple of things more and upload a new version in a couple of days. I will write you back here once ready :)

victordiaz commented 4 years ago

I close the issue. There is a lot of rework in the last release, maybe hopefully was fixed? :)