I am trying to upload an image from my local System to blob storage in Azure. I am getting my image name but how to get the full path of image that I have selected?
This is what I have done:
class Uploadfile @Inject() (implicit val messagesApi: MessagesApi, ec: ExecutionContext) extends Controller with i18n.I18nSupport
{
var path="";
val dbConfig = Database.forURL("jdbc:mysql://localhost:3306/equineapp?user=root&password=123456", driver = "com.mysql.jdbc.Driver")
def upload(HorseId : Int) = Action(parse.multipartFormData) { request =>
request.body.file("picture").map { picture =>
val filename = Paths.get(picture.filename).getFileName /// from here i am geeting Image name
var connString="DefaultEndpointsProtocol=https;AccountName=XXXXXXXXXXXXX;AccountKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==;EndpointSuffix=core.windows.net";
val account = CloudStorageAccount.parse(connString)
val serviceClient = account.createCloudBlobClient
// Container name must be lower case.
val container = serviceClient.getContainerReference("myimages")
container.createIfNotExists
// Upload an image file.s
val blob = container.getBlockBlobReference(filename.toString())
//var path =filename.getRoot
//def absolutePath: String = new File(filename).getAbsolutePath();
var pathimage=filename.getFileSystem//// how to get full path of selected Image
val sourceFile = new File(pathimage.toString())
blob.upload(new FileInputStream(sourceFile), sourceFile.length)
// val setup1 = sql"call horseimagepath ($HorseId, $path);".as[(String)]
// val res = Await.result(dbConfig.run(setup1), 1000 seconds)
Ok("File uploaded"+filename+ sourceFile)
}.getOrElse {
Redirect(routes.HomeController.index()).flashing(
"error" -> "Missing file")
}
}
}
If I hard code the image full path then I am not getting any exception but how to get full path of image dynamically?