如何重命名目标c中捕获的图像?
在我的应用程序中,我需要捕获图像并将其保存在本地库和使用 FTP 的服务器上。现在我需要在将图像保存在服务器上时遵循图像名称的格式。我能够捕获图像并将其保存在本地库中。但我找不到任何方法来更改图像的名称。假设我需要将其重命名为 Productname-UserId.png 有什么办法吗?请帮忙。
谢谢。
In my application I need to capture image as well as save it on local library and on server using FTP. Now I need to follow a format for image name while saving it on the server. I am able to capture and save the image on local library. But I am unable to find any method to change the name of the Image. Suppose I need to rename it as Productname-UserId.png Is there any way? Kindly help.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里真正的问题是您希望文件名具体在哪里?在设备上或服务器上。如果设备使用 Charles 答案,否则您应该查看 http 协议(文件上传部分)。实际上,文件在本地设备上的名称并不重要,因为当您通过 http 将其发送到服务器时,您可以提供任何名称。这里棘手的部分是,您上传到的服务器在保存该文件时应考虑该参数。因此,如果您要上传到您手头没有的服务器,并且它执行一些自命名约定 - 您可能会陷入困境。如果是您的 - 看看您如何在服务器端保存文件,以及您是否考虑了“文件名”参数...
PS 并且不要忘记将该参数传递给上传要求 :)
The real question here is where do you want the file name to be specific? On the device or on the server. In case of device use Charles answer, otherwise you should look at http protocol(file upload part). Actually it doesn't matter what name the file have on you local device, as when you send it to the server over http, you can provide any name. The tricky part here is that the server you are uploading to should take that parameter into account when saving that file. So if you are uploading to a server that you don't have hand on and it does some self naming convention - you probably stuck. If it's yours - look at how you're saving files on the server side and if you are taking in account that "filename" parameter...
P.S. And don't forget to pass that argument to the upload request :)
UIImagePNGRepresentation(UIImage*) 可能就是您正在寻找的。您可以将 UIImage 作为 PNG 文件保存在应用程序文档文件夹中,然后将其上传到服务器。执行此操作的代码非常简单,因此如果您可以发布您尝试使用的代码,这将有助于理解并为您推荐解决方案。
这是我的代码中的一个简短剪辑,它正是执行此操作:
其中 applicationDocumentsDirectory 如下所示:
UIImagePNGRepresentation(UIImage*) is likely what you're looking for. You can save a UIImage as a PNG file in the Application Documents folder, then upload that to a server. The code to do this is quite trivial, so if you could post the code you're trying to use, that would be helpful to understanding, and recommending a solution for you.
Here's a short clipping from my code that does exactly this:
Where applicationDocumentsDirectory looks like this: