$cordovafiletransfer.upload怎么传参

$cordovafiletransfer.upload怎么传参,第1张

html代码:

<!DOCTYPE html>

<!--

Licensed to the Apache Software Foundation (ASF) under one

or more contributor license agreements. See the NOTICE file

distributed with this work for additional information

regarding copyright ownership. The ASF licenses this file

to you under the Apache License, Version 2.0 (the

"License")you may not use this file except in compliance

with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,

software distributed under the License is distributed on an

"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

KIND, either express or implied. See the License for the

specific language governing permissions and limitations

under the License.

-->

<html>

<head>

<meta charset="utf-8" />

<meta name="format-detection" content="telephone=no" />

<meta name="msapplication-tap-highlight" content="no" />

<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->

<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />

<link rel="stylesheet" type="text/css" href="css/index.css" />

<title>Hello World</title>

</head>

<body>

<div class="app">

<h1>Apache Cordova</h1>

<div id="deviceready" class="blink">

<p class="event listening">Connecting to Device</p>

<p class="event received">Device is Ready</p>

</div>

</div>

<script type="text/javascript" src="cordova.js"></script>

<script type="text/javascript" src="js/index.js"></script>

<!-- 照相机 -->

<script type="text/javascript" src="js/camera.js"></script>

<input type="button" value="take pictures" onclick="snapPictures()" />

<img style="width:100pxheight:100pxposition:absoluteleft:100pxtop:50px" id="myImage" />

<!-- 地理位置 -->

<script type="text/javascript" src="js/geolocation.js"></script>

<input type="button" value="location" onclick="getLocation()" />

<!-- 文件传输 -->

<script type="text/javascript" src="js/fileTransfer.js"></script>

<input type="button" value="fetchFile" onclick="fetchPictures()" />

<!-- <input type="button" value="fileTransfer" onclick="startTransfer()" />-->

</body>

</html>

js代码:

/**选择图片库***/

function fetchPictures(){

navigator.camera.getPicture(fetchPictureSuccess, fetchPictureFail, {

quality: 50,

destinationType: Camera.DestinationType.FILE_URI,//存储照片的数据/路径

sourceType : Camera.PictureSourceType.PHOTOLIBRARY ,//打开系统的图片库

encodingType: Camera.EncodingType.JPEG,

mediaType:Camera.MediaType.PICTURE,

popoverOptions : CameraPopoverOptions,

saveToPhotoAlbum: true

})

}

function fetchPictureSuccess(imageURI) {

var image = document.getElementById('myImage')

image.src = imageURI

picUrl = imageURI

/**文件上传start***/

var serverUri = encodeURI('http://192.168.1.101:8080/testTransfer/test.do')

function fileTransferSuccess(result) {

alert("success")

alert("Code = " + result.responseCode + "Response = " + result.response

+ "Sent = " + result.bytesSent)

}

function fileTransferError(error) {

alert("fail")

alert("An error has occurred: Code = " + error.code + "upload error source " + error.source

+ "upload error target " + error.target)

}

var fileUploadOptions = new FileUploadOptions()

fileUploadOptions.fileKey = "file"

fileUploadOptions.fileName = picUrl.substr(picUrl.lastIndexOf('/')+1)

fileUploadOptions.mimeType = "image/jpeg"

//fileUploadOptions.chunkedMode = false

var fileTransfer = new FileTransfer()

alert("picUrl : "+picUrl + "******serverUri : " + serverUri)

// fileTransfer.onprogress = function(progressEvent) {

//if (progressEvent.lengthComputable) {

// loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total)

//} else {

// loadingStatus.increment()

//}

// }

fileTransfer.upload(picUrl, serverUri,fileTransferSuccess, fileTransferError, fileUploadOptions)

/**文件上传end***/

}

function fetchPictureFail(message) {

alert('Failed because: ' + message)

}

server端JAVA:

package com.cn.server

import java.io.File

import java.io.IOException

import java.net.URLDecoder

import java.util.Iterator

import java.util.List

import javax.servlet.ServletException

import javax.servlet.annotation.WebServlet

import javax.servlet.http.HttpServlet

import javax.servlet.http.HttpServletRequest

import javax.servlet.http.HttpServletResponse

import org.apache.commons.fileupload.FileItem

import org.apache.commons.fileupload.FileItemFactory

import org.apache.commons.fileupload.disk.DiskFileItemFactory

import org.apache.commons.fileupload.servlet.ServletFileUpload

/**

* Servlet implementation class Test

*/

@WebServlet("/Test")

public class Test extends HttpServlet {

private static final long serialVersionUID = 1L

/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

System.out.println("Doing post....")

System.out.println(request.getRequestURI())

/**

* The base upload directory. In this directory all uploaded files will

* be stored. With the applet param tag 'directory' you can create a

* subdirectory for a user.

* See http://www.javaatwork.com/parameters.html#directory for more

* information about the 'directory' param tag. For a Windows environment

* the BASE_DIRECTORY can be e.g. * 'c:/temp' for Linux environment '/tmp'.

*/

boolean isMultipart = ServletFileUpload.isMultipartContent(request)

// check if the http request is a multipart request

// with other words check that the http request can have uploaded files

if (isMultipart) {

// Create a factory for disk-based file items

FileItemFactory factory = new DiskFileItemFactory()

// Create a new file upload handler

ServletFileUpload servletFileUpload = new ServletFileUpload(factory)

// Set upload parameters

// See Apache Commons FileUpload for more information

// http://jakarta.apache.org/commons/fileupload/using.html

servletFileUpload.setSizeMax(-1)

try {

String directory = ""

// Parse the request

List items = servletFileUpload.parseRequest(request)

// Process the uploaded items

Iterator iter = items.iterator()

while (iter.hasNext()) {

FileItem item = (FileItem) iter.next()

// the param tag directory is sent as a request parameter to

// the server

// check if the upload directory is available

if (item.isFormField()) {

String name = item.getFieldName()

if (name.equalsIgnoreCase("directory")) {

directory = item.getString()

}

// retrieve the files

} else {

// the fileNames are urlencoded

String fileName = URLDecoder.decode(item.getName())

File file = new File(directory, fileName+".jpeg")

file = new File("D:\\androidApp图片\\", file.getPath())

// retrieve the parent file for creating the directories

File parentFile = file.getParentFile()

if (parentFile != null) {

parentFile.mkdirs()

}

// writes the file to the filesystem

item.write(file)

}

}

} catch (Exception e) {

e.printStackTrace()

response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)

}

response.setStatus(HttpServletResponse.SC_OK)

} else {

response.setStatus(HttpServletResponse.SC_BAD_REQUEST)

}

}

/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

doGet(request,response)

}

}

server端web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

<display-name>testTransfer</display-name>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

<welcome-file>index.htm</welcome-file>

<welcome-file>index.jsp</welcome-file>

<welcome-file>default.html</welcome-file>

<welcome-file>default.htm</welcome-file>

<welcome-file>default.jsp</welcome-file>

</welcome-file-list>

<servlet>

<servlet-name>Test</servlet-name>

<servlet-class>com.cn.server.Test</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Test</servlet-name>

<url-pattern>/test.do</url-pattern>

</servlet-mapping>

需要下载WPS、microffice等办公软件。

下载方法:

1、使用 Apple ID 在 App Store中下载即可。

2、打开手机主屏上的 App Store 应用。

3、点击底下的“搜索”栏目。

4、在顶部的搜索框中输入以上的关键字,点击键盘上的“搜索”键。

5、点击免费安装按钮,输入id和密码即可开始下载。

6、下载完毕安装完成后,找到文档,点击打开,然后选择打开的应用程序,然后选择以上软件,即可在办公软件中打开,并保存带这些软件中。

之前上架过两三款App,都是使用Hbuilder打包进行上传的。众所周知,vue编译好之后使用Hbuilder打包比较简单,快捷。但是又很多兼容性方面是Hbuilder官方都无法解决的。更令人头痛的是,Hbuider打包后的vue项目,编译成ios的ipa文件上传到苹果商店之后,很容易被驳回,驳回的理由仍然是二进制文件被拒绝。Guideline 4.3 - Design 被视为马甲包或者垃圾邮件。然而使用Xcode打包上传的应用则不会被以这样的问题驳回。经过无数次采坑,总结如何使用Xcode打包vue文件并且提交到AppStore。

这点大家应该都会,写好的vue项目直接

打包好放在一边,备用。

1.安装cordova命令工具

前提是:

电脑已经安装好Node.js

2.打开cmd

-g代表全局安装

验证安装成功:

命令行内继续输入:

出现下图表明安装成功

1.新建文件夹作为你的App目录,桌面新建任意名称文件夹(建议不要用中文!!!)

2.使用命令行进入刚刚创建的文件夹,然后使用命令行输入:

上面的命令意思就是:使用cordova 创建一个 项目名为App ,包名是com. ,App名是AppName

注意,com.xxx需要与你App Store的账号内注册的包名一样

执行完上面的命令,你在打开刚刚创建的文件夹内,肯定就会有一个WWW的文件夹,如图

一定要在Cordova创建的项目下执行以下命令,而不是在WWW文件夹内!!!

执行完以上命令后,在执行

以上命令执行完,打开创建的文件夹,应该就会有下面这个‘platforms’文件夹了,进入这个文件夹,文件夹内会有一个IOS文件夹,然后再进去就能看到下图的样子

安装好Xcode的朋友直接双击XXXXXX.xcodeproj 这个文件,会自动使用Xcode打开

前提条件,已经将App基本信息配置完毕,然后再点击 Generic IOS Device!!!

勾选Generic IOS Device

勾选后点击头部的Product,选择 Archive

点击推送之后就是小白 *** 作了 一直点击next下一步知道上传完成即可!不懂的欢迎留言讨论。

本人文章写得可能不够详细,或者比较繁琐,如果哪位大神有更好的方法或者建议,可以直接评论。

不明白的可以留言或加我讨论!

感谢你们的阅读!谢谢!


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11652908.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存