如何解决使用alamofire上载pdf文件
我有下面的函数是通过sw脚的代码生成的:
open class func uploadFile(firstname: String,lastname: String,timestamp: Date,file: URL,completion: @escaping ((_ data: ApiResponse?,_ error: Error?) -> Void)) {
在该应用中,您可以使用相机制作图像并将图像转换为pdf文件:
let document = PDFDocument()
let pdfPage = PDFPage(image: unwrapImage)
document.insert(pdfPage!,at: 0)
所以现在我要上传此文档。但是document.documentURL
始终为零。尽管我可以在显示屏上显示pdf文档。我是否应该将pdf文档保存到临时目录中,以将函数与url参数一起使用?
解决方法
PDFDocument的属性# -*- coding: utf-8 -*-
# Sample Python code for youtube.videos.update
# See instructions for running these code samples locally:
# https://developers.google.com/explorer-help/guides/code_samples#python
import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]
def main():
# Disable OAuthlib's HTTPS verification when running locally.
# *DO NOT* leave this option enabled in production.
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "client_secret_key.json"
# Get credentials and create an API client
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file,scopes)
credentials = flow.run_console()
youtube = googleapiclient.discovery.build(
api_service_name,api_version,credentials=credentials)
request = youtube.videos().update(
part="id,snippet",body={
"id": "videoid","snippet": {
"title": "XOXOXO","description": "Through IDE","categoryId": "27"
}
}
)
response = request.execute()
print(response)
if __name__ == "__main__":
main()
仅获得。如果不使用url初始化程序,它将始终返回nil。您需要将PDFDocument documentURL
和dataRepresentation
的pdf数据保存到临时或永久位置的url中。然后,您可以上传其URL。
write
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。