到目前为止,我已经使用 Twisted 框架为聊天应用程序开发了一个服务器,但我很难弄清楚如何实现存储某个人的照片。
我的第一个想法是我可以在本地存储图像 [这是最好的方法吗] 并如此处理它,但正如我之前所说,我无法弄清楚如何解析照片。我的意思是如何发送它到服务器?
照片应该从客户端[iOS 应用程序] 中选择并发送到服务器,但正如我所说,我不明白它是如何工作的。
我应该在 dataReceived 中添加一些东西还是应该做其他事情?
到目前为止我做了什么
from twisted.internet import reactor
from twisted.internet.protocol import Factory , Protocol
class IphoneChat(Protocol):
def connectionMade(self):
self.factory.clients.append(self)
def connectionLost(self , reason):
self.factory.clients.remove(self)
def dataReceived(self,data):
#do a lot of processing which works
factory = Factory()
factory.protocol=IphoneChat
factory.clients = []
reactor.listenTCP(8023,factory)
print "IPhone Chat server started"
reactor.run()
任何建议或想法都会对我很有帮助。
最佳答案
解决方案可能是:
- 将图像转换为
blob
或binary
格式并发送到服务器。 - 你又可以把它转换成原来的格式
关于python - 使用 Twisted 在服务器中存储图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25738634/